Convert a Standalone to a Replica Set¶
This tutorial describes the process for converting a standalone mongod instance into a three-member replica set. Use standalone instances for testing and development, but always use replica sets in production. To install a standalone instance, see the installation tutorials.
Restart the instance. Use the --replSet option to specify the name of the new replica set.
For example, the following command starts a standalone instance as a member of a new replica set named rs0. The command uses the standalone’s existing database path of /srv/mongodb/db0:
mongod --port 27017 --dbpath /srv/mongodb/db0 --replSet rs0
If your application connects to more than one replica set, each set should have a distinct name. Some drivers group replica set connections by replica set name.
Connect to the mongod instance.
Use rs.initiate() to initiate the new replica set:
The replica set is now operational.
Expand the Replica Set¶
Add additional replica set members by doing the following:
On your connection to the original mongod instance (the former standalone instance), issue a command in the following form for each new instance to add to the replica set: