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:
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, 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.
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?
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.