Restart MongoDB Replica Set

For Secondary Node

Step-1 Login to mongo shell on Secondary servers

$ mongo -u user123 -p --authenticationDatabase admin (If your DB has authentication enabled)

Step-2 Stop the secondary servers by using below command :

> use admin
> db.shutdownServer()

Step-3 Go to Linux shell on secondary servers and type below command :

> sudo service mongod stop

Starting the MongoDB replication

Step-4 Go to Linux shell on secondary servers and type below command :

> sudo service mongod start

Step-5 Check the status

> sudo systemctl status mongod.service

For Primary Node

Step-1 Login to primary as in Step-1

Step-2 Step Down Primary Node

> rs.stepDown(120)

Connect mongo shell to the primary node and use rs.stepDown() to step down the primary and allow one of the secondary to be elected the new primary. Specify a 120-second waiting period to prevent the member from being elected primary again.

Perform step-2, step-3, step-4 and step-5.

Last updated

Was this helpful?