Consider, I have 4 replicate sets and the config is as follows:
{
"_id": "rs_0",
"version": 5,
"members" : [
{"_id": 1, "host": "127.0.0.1:27001"},
{"_id": 2, "host": "127.0.0.1:27002"},
{"_id": 3, "host": "127.0.0.1:27003"},
{"_id": 4, "host": "127.0.0.1:27004"}
]
}
I am able to connect to all sets using
mongo --port <port>
There are documents for getting information on Convert a Standalone to a Replica Set, but can anyone tell me how to convert back to standalone from replica set?
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:
to remove the warning you can do 2 procedures: 1) Droping the local db and restarting mongo:
2)Or if you don't want to be so radical, you can do:
and it will prompt a message like:
then you will erase it using:
and it will probably prompt:
Now, you can restart the mongo and the warning should be gone, and you will have your mongo in standalone mode without warnings
1) Go to mongo shell on Secondary servers
2) Stop the secondary servers by using below command:
After executing below command. Your primary will automatically become stand alone server.
For more information, please check the below link: http://www.tutespace.com/2016/03/stopping-and-starting-mongodb.html
On an Ubuntu Machine
Just remove a host from replica set (
rs.remove('host:port')
), relaunch it withoutreplSet
parameter and it's standalone again.The MongoDB Documentation suggests the following to perform maintenance on a replica set member, which brings the the replica set member into standalone mode for further operations. With little modification it can be made standalone:
sh.startBalancer(timeout, interval)
db.adminCommand( { removeShard: "mongodb0" } )
rs.stepDown(300)
db.shutdownServer()
rs.remove("host:port")
After this, the node in concern should be up and running in standalone mode.