Skip to content

Instantly share code, notes, and snippets.

@matthewhartstonge
Last active April 9, 2017 22:59
Show Gist options
  • Save matthewhartstonge/f81c5a8cade0795e2eef73b2919c58ad to your computer and use it in GitHub Desktop.
Save matthewhartstonge/f81c5a8cade0795e2eef73b2919c58ad to your computer and use it in GitHub Desktop.
Start Mongo Replicaset up again after hard power off or restarting all hosts or containers
/**
* This script forces the first node in the config list to be master
*/
cfg = rs.conf()
cfg.members[0].priority = 1
cfg.members[1].priority = 0.5
cfg.members[2].priority = 0.5
rs.reconfig(cfg, {force: true})
// This one liner will force the replica set to restart re-election if hostnames haven't changed.
rs.reconfig(rs.conf(), {force: true});
/**
* If hostnames need to be reconfigured for whatever reason, use the following lines to readjust the replica set configuration
*/
// cfg = rs.conf();
// cfg.members[0].host = "192.168.0.1:27017"
// cfg.members[1].host = "123.123.123.123:27017"
// cfg.members[2].host = "mongodb-hostnames-work-here-too:27017"
// rs.reconfig(cfg, {force: true});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment