Previous session data not persisting in MongoDB

I am using a local instance of MongoDB using the command mongo. Using mongosh, I created a couple of dbs and collections and insert some data.

After performing the required operations, I needed to shut down the server. Following the docs, I entered db.shutdownServer() but get the error Error: read ECONNRESET. I then tried using the alternative methods and used Control-C in the terminal instance where the server was running. It shut down.

When I restarted the server to perform some operations, I could not find the dbs I created in the last session.

  1. Is this the intended behavior? If yes, how can I ensure cross-session data persistence?
  2. Was the session termination a clean shutdown in my case?
  3. How can I troubleshoot the error encountered while using db.shutdownServer()?

Hi @Praneet_Dixit

The message Error: read ECONNRESET is from the mongosh client. The server was shutdown and now the client connection is reset, this is an expected message.

This CTRL+C is exiting the mongosh client, the server was already shutdown.

This would depend on how the server was started. The same --dbpath (or configuration file) would need to be specified so the same database data files.

For local development the atlas cli can be used to create and manage local deployments with the added benefit of supporting Full Text Search and Vector Search.

1 Like