How to shut down replica set in mongodb?
1) Login to mongo shell on Secondary servers
2) Stop the secondary servers by using below command:
use admin
db.shutdownServer()
2] Go to Linux shell- on secondary servers and type below command:
sudo service mongod stop
For more information, Please check the below link:
http://www.tutespace.com/2016/03/stopping-and-starting-mongodb.html
I don't think the accepted answer is correct. After some googling, I found this in mongodb-user group to be the best answer.
To shutdown:
- Rundb.runCommand({ replSetFreeze: numOfSeconds })
on secondaries to prevent from promoting to primary
- Runrs.stepDown(seconds)
on the primary; it will check to make sure at least one of the secondaries is sufficiently caught up to oplog before stepping down. Choose a reasonably long wait time.
- Once everything is a secondary,db.shutdownServer()
on everythingTo start up:
- Runrs.freeze(seconds)
on both secondaries with a lengthy timeout (say, 1-2 minutes)
- Bring up primary
- Use stepDown to fix in case a secondary somehow becomes primary
Simply shutting down is not enough, you have to prevent secondary nodes from promoting to primary.
Run the following commands from the Unix shell:
mongo --port 27017 --eval 'db.adminCommand("shutdown")'
mongo --port 27018 --eval 'db.adminCommand("shutdown")'
mongo --port 27019 --eval 'db.adminCommand("shutdown")'