March 6, 2023, 9:15am
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 .
March 7, 2023, 4:08am
@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:
Shutdown the stand alone database.
Restart the process using --replSet in your deployment.
Add secondaries to the primary mongod process.
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,
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.
March 7, 2023, 6:31pm
page says the instance can just be restarted wish a replica set name , no mentioning about data import/export at all.
March 9, 2023, 12:25am
@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?
March 15, 2023, 3:51am
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,
If your data size is large, you can
resync the replica set member to speed up the process. 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.