Skip to main content

Converting a Standalone Mongod to a Replicas Set

By October 26, 2021October 27th, 2021No Comments

In this blog, I am going to explain how we can convert or migrate standalone mongoDB to replica sets also design standalone servers and replicaset. Basically, for Development and QA environment we can use standalone but for production, a replica set is the best option to set up.

Pros with Standalone mongo server :

  1. Single server maintenance.
  2. Easy to manage.

Problem with Standalone mongo server :

You don’t have high availability. Thus it’s not recommended for production deployment. This is fine for development though. A standalone is an instance of mongod that runs on a single server but is not part of a replica set.

MongoDB in production was designed with a replica set deployment in mind, for:

  1. High availability in the face of node failures
  2. Rolling maintenance/upgrades with no downtime
  3. Possibility to scale-out reads
  4. Possibility to have a replica of data in a special-purpose node that is not part of the high availability nodes

Before starting to migrate the database please have a backup of the database and server. We can convert Standalone to Replicase set in below 5 Steps.

  1. Shut down the standalone mongod instance.

sudo systemctl stop mongod

2. Start the instance. Use the — replSet option to specify the name of the new replica set.

mongod — port 27017 — dbpath /srv/mongodb/db0 — replSet rs0 — bind_ip localhost

3. Check the log file and confirm it is not stuck and waiting. Default Location “/var/log/mongodb/mongod.log”

tail -f /var/log/mongodb/mongod.log

4. Connect to mongosh to the mongod instance.

5. Initiate replicaset instance


6. The replica set is now operational. To view the replica set configuration, use rs.conf(). To check the status of the replica set

use rs.status()