Skip to content

Instantly share code, notes, and snippets.

@jbutko
Last active April 24, 2019 11:48
Show Gist options
  • Save jbutko/aec71409f420865566d1f6358d547e7c to your computer and use it in GitHub Desktop.
Save jbutko/aec71409f420865566d1f6358d547e7c to your computer and use it in GitHub Desktop.
MongoDB: How to force rs slave to become primary

In a mongo shell, run rs.status() to ensure your replica set is running as expected.

In a mongo shell connected to the mongod instance running on mdb2.example.net, freeze mdb2.example.net so that it does not attempt to become primary for 120 seconds.

rs.freeze(120)

In a mongo shell connected the mongod running on mdb0.example.net, step down this instance that the mongod is not eligible to become primary for 120 seconds:

rs.stepDown(120)

mdb1.example.net becomes primary.

via https://docs.mongodb.com/manual/tutorial/force-member-to-be-primary/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment