Replace a Replica Set Member
If you need to change the hostname of a replica set member withoutchanging the configuration of that member or the set, you can use theoperation outlined in this tutorial. For example if you mustre-provision systems or rename hosts, you can use this pattern tominimize the scope of that change.
Operation
To change the hostname for a replica set member modify themembers[n].host
field. The value ofmembers[n]._id
field will not changewhen you reconfigure the set.
See Replica Set Configuration andrs.reconfig()
for more information.
Note
Any replica set configuration change can trigger the currentprimary to step down, which forces an election. During the election, the current shellsession and clients connected to this replica set disconnect,which produces an error even when the operation succeeds.
Example
To change the hostname to mongo2.example.net
for the replica setmember configured at members[0]
, issue the following sequence ofcommands:
- cfg = rs.conf()
- cfg.members[0].host = "mongo2.example.net"
- rs.reconfig(cfg)