How to convert a MongoDB replica set to a stand alone server

Just remove a host from replica set (rs.remove('host:port')), relaunch it without replSet parameter and it's standalone again.


Remove all secondary hosts from replica set (rs.remove('host:port')), restart the mongo deamon without replSet parameter (editing /etc/mongo.conf) and the secondary hosts starts in standalone mode again.

The Primary host is tricky one, because you can't remove it from the replica set with rs.remove. Once you have only the primary node in the replica set, you should exit mongo shell and stop mongo. Then you edit the /etc/mongo.conf and remove the replSet parameter and start mongo again. Once you start mongo you are already in standalone mode, but the mongo shell will prompt a message like:

2015-07-31T12:02:51.112+0100 [initandlisten] ** WARNING: mongod started without --replSet yet 1 documents are present in local.system.replset

to remove the warning you can do 2 procedures: 1) Droping the local db and restarting mongo:

use local
db.dropDatabase();

/etc/init.d/mongod restart

2)Or if you don't want to be so radical, you can do:

use local
db.system.replset.find()

and it will prompt a message like:

{ "_id" : "replicaSetName", "version" : 1, "members" : [ { "_id" : 0, "host" : "hostprimary:mongoport" } ] }

then you will erase it using:

db.system.replset.remove({ "_id" : "replicaSetName", "version" : 1, "members" : [ { "_id" : 0, "host" : "hostprimary:mongoport" } ] })

and it will probably prompt:

WriteResult({ "nRemoved" : 1 })

Now, you can restart the mongo and the warning should be gone, and you will have your mongo in standalone mode without warnings