Downgrade MongoDB replica set to a standalone node

Adela Chao
Oct 26, 2020

--

Now you have a MongoDB replica set and decide to downgrade it to a standalone node.

If you don’t have a replica set yet, please refer to my previous post Create a MongoDB replica set to create one to go through this article.

Remove secondary member nodes

Firstable, Shut down the mongod instance for the member you wish to remove.

Then connect to the replica set’s current primary instance.

Use rs.remove() to remove the secondary member :

rs.remove("127.0.0.1:27027")
rs.remove("127.0.0.1:27037")

Check replica set status to ensure now only Primary member is left alone.

Remove replication setting

Delete or comment replication setting in mongod.cfg file

#replication:
#replSetName: rs0

On Windows, a default <install directory>/bin/mongod.cfg configuration file is included during the installation.

Shut down the Primary mongod instance.

Restart MongoDB service if you have installed it as a service.

Restart mongod instance as a single node:

mongod --port 27017 --dbpath="C:\data\db0"

To be completely sure that the replica set configuration is removed from the instance, connect to this instance and empty local.system.replset collection :

use localdb.system.replset.remove({})

Also drop other replica set related collections :

db.replset.election.drop()db.replset.minvalid.drop()

Now welcome back to our standalone instance ! 😃

You can then restart with a different replSet argument and create a new replica set again.

--

--

No responses yet