Non-voting members allow you to add additional members for read distribution beyond the maximum seven voting members.
To configure a member as non-voting, use the
replSetReconfig command or its
mongo shell helper rs.reconfig() to set its
members[n].votes and members[n].priority values to
0. Non-voting replica set members must have a
priority of 0.
Note
Starting in MongoDB 4.4, replica reconfiguration can add or remove no
more than one voting replica set member at a time. To modify the
votes of multiple members, issue a series of
replSetReconfig or rs.reconfig() operations to
modify one member at a time. See
Reconfiguration Can Add or Remove No More than One Voting Member at a Time for more information.
Procedure
The following procedure converts configures a single secondary
replica set member to be non-voting. To convert the primary
member to be non-voting, you must first successfully step the primary
down using replSetStepDown or its shell helper
rs.stepDown() before performing this procedure.
- 1) Connect to the Replica Set Primary
Connect a
mongoshell to the replica set primary:mongo --host "<hostname>:<port>" Replace the
<hostname>and<port>with the hostname and port of the replica set primary. Include any other parameters required for your deployment.- 2) Retrieve the Replica Configuration
Issue the
rs.conf()method in the shell and assign the result to a variablecfg:cfg = rs.conf(); The returned document contains a
membersarray, where each element in the array contains the configuration for a single replica set member.- 3) Configure the Member to be Non-Voting
For the replica member to change to be non-voting, set its
votesandpriorityto0.cfg.members[n].votes = 0; cfg.members[n].priority = 0; Replace
nwith the array index position of the member to modify. Themembersarray is zero-indexed, where the first element in the array has an index position of0.The array index position of a member in the
membersarray is distinct from themembers[n]._idof a specific member. Do not use the_idto reference the array index position of any any member inmembers.- 4) Reconfigure the Replica Set with the New Configuration
Use
rs.reconfig()method to reconfigure the replica set with the updated replica set configuration document.rs.reconfig(cfg);
Warning
The
rs.reconfig()shell method can force the current primary to step down, which causes an election. When the primary steps down, themongodcloses all client connections. While this typically takes 10-20 seconds, try to make these changes during scheduled maintenance periods.Avoid reconfiguring replica sets that contain members of different MongoDB versions as validation rules may differ across MongoDB versions.