Database migration from standalone machine to cluster

Hi all ,

Currently i have an production live standalone mongodb server which is connected to an express nodejs application , now i went ahead and setup a replica set (3 machines) . Now how do i migrate data from this live DB to my replica set without any loss of data .

Hi @Stuart_S and welcome to the MongoDB Community forum!!

There could be two different ways to migrate from a standalone to a replica set.

Case 1: If you have no data in your database and you only have a deployment

The steps for the following are:

  1. Shutdown the stand alone database.
  2. Restart the process using --replSet in your deployment.
  3. Add secondaries to the primary mongod process.
  4. Connect you application with the primary of the replica set.

Case 2: If you have a large collection in your database in the stand alone deployment:

The MongoDB tools mongoexport will convert the collection into the format of the choice and further the mongoimport.
Further, you can also use mongodump and mongorestore for the process.

However, please note that, mongoexport and mongoimport does not import and export the indexes in MongoDB. Hence you would be required to create index if using the former method.

Also, please refer to the documentation on How to Convert a standalone to replica set for further information.

Let us know if you have any further queries.

Best Regards


But this page says the instance can just be restarted wish a replica set name , no mentioning about data import/export at all.

Thanks @Aasawari for the answer
I do have the Case 2 to do , but for live data and data that will be coming in continously, mongoexport or mongodump which is better?

Hi @Stuart_S

For live data migration, you need to convert the stand alone replica set to a single node replica set and then pull the data to Atlas.

Please note that, as per the documentation, you cannot user M0/M2/M5 shared tier clusters as source or destination for live migration.

To add more details to the above information,

  1. If your data size is large, you can resync the replica set member to speed up the process.
  2. If you wish to move data to Atlas, you can follow the documentation for the same.

Please note that, the process can potentially be disruptive, hence the recommendation is to test the workload before performing on the production environment.

Let us know of you have further questions.

Best Regards