Database migration from standalone machine to cluster

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
Aasawari

2 Likes