Changing priority to replica set nodes
By now, you would have noticed the priority
keyword in the rs.status()
output. Replica set members with higher priorities are more likely to be elected as primaries. The value of a priority can range from 0
to 1000
, where 0
indicates a non-voting member. A non-voting member functions as a regular member of a replica set but cannot vote in elections nor get elected as a primary.
Getting ready
For this recipe, we need a three node replica set.
How to do it...
- 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()
- Change the priorities of all members:
conf['members'][0].priority = 5 conf['members'][1].priority = 2 conf['members'][2].priority = 2
- Reconfigure the replica set:
rs.reconfig(conf)
- Check the new configuration:
rs.conf()['members']
How it works...
Like our previous recipe, we connect to the primary node and fetch the replica set configuration object. Next, in step...