Configure Non-Voting Replica Set Member
Non-voting members allow you to add additional members for readdistribution beyond the maximum seven voting members.
Important
Changed in version 3.2:
Non-voting members must have
priority
of 0.
To configure a member as non-voting, set both itsvotes
and priority
values to0
.
Example
The following example configures the fourth, fifth, and sixth replicaset members to be non-voting members.
- In a
mongo
shell connected to a primary, run thers.conf()
method and assign the result to a variable:
- cfg = rs.conf();
The returned document contains a members
field which contains azero-indexed array of member configuration documents, one document for eachmember of the replica set.
- To configure the fourth, fifth, and sixth replica set members to benon-voting, use the following command sequence to set both their
members[n].votes
andmembers[n].priority
valuesto0
.
- cfg.members[3].votes = 0;
- cfg.members[3].priority = 0;
- cfg.members[4].votes = 0
- cfg.members[4].priority = 0;
- cfg.members[5].votes = 0
- cfg.members[5].priority = 0;
- Use
rs.reconfig()
method to reconfigure the replica setwith the updated replica set configuration document.
- rs.reconfig(cfg);
Place voting members so that the mongod
instance or instancesthat you wish to serve as primary canreach a majority of votes in the event of a network partition.
Use members[n].priority
to control which members are more likely to become primary.
When updating the replica configuration object, access the replica setmembers in the members
array with thearray index. The array index begins with 0
. Do not confusethis index value with the value of themembers[n]._id
field in each document inthe members
array.
Warning
- The
rs.reconfig()
shell method can force the currentprimary to step down, which causes an election. When the primary steps down, themongod
closes all client connections. While thistypically takes 10-20 seconds, try to make these changes duringscheduled maintenance periods. - Avoid reconfiguring replica sets that contain members of differentMongoDB versions as validation rules may differ across MongoDB versions.