Up until now, we were performing replica set modifications using helper functions like rs.add()
, rs.remove()
, and so on. As mentioned earlier, these functions are wrappers which modify the replica set configuration. In this recipe, we will be looking at how to fetch and change the replica set configuration. This can be helpful for various operations like setting priorities, delayed nodes, changing member hostnames, and so on.
- Connect to the primary member of the replica set using the mongo shell:
mongo mongodb://192.168.200.200:27017
- Fetch the configuration:
conf = rs.conf()
- Remove the third member of the replica set:
conf['members'].pop(2)
- Reconfigure the replica set:
rs.reconfig(conf)
- Confirm that the third node was removed by inspecting the output of
rs.status()
:
rs.status()['members']
- Add the third node back to the replica set:
member = {"_id": 2, "host": "192.168.200.200:27019...