On this page本页内容
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 mongosh
helper method rs.reconfig()
to set its members[n].votes
and members[n].priority
values to 0
. replSetReconfig
命令或其mongosh
助手方法rs.reconfig()
将其members[n].votes
和members[n].priority
值设置为0
。Non-voting replica set members must have a 非投票副本集成员的priority
of 0
.priority
必须为0
。
Starting in MongoDB 4.4, replica reconfiguration can add or remove no more than one voting replica set member at a time. 从MongoDB 4.4开始,副本重新配置一次最多可以添加或删除一个投票副本集成员。To modify the votes of multiple members, issue a series of 要修改多个成员的投票,请执行一系列replSetReconfig
or rs.reconfig()
operations to modify one member at a time. replSetReconfig
或rs.reconfig()
操作,一次修改一个成员。See Reconfiguration Can Add or Remove No More than One Voting Member at a Time for more information.有关详细信息,请参阅重新配置可一次添加或删除不超过一个投票成员。
The following procedure converts configures a single secondary replica set member to be non-voting. 以下转换过程将单个secondary副本集成员配置为无投票。To convert the primary member to be non-voting, you must first successfully step the primary down using 要将primary成员转换为无投票成员,必须首先使用replSetStepDown
or its shell helper rs.stepDown()
before performing this procedure.replSetStepDown
或其shell助手rs.stepDown()
成功地将主要成员降级,然后才能执行此过程。
Connect 将mongosh
to the replica set primary:mongosh
连接到副本集primary:
mongosh --host "<hostname>:<port>"
Replace the 将<hostname>
and <port>
with the hostname and port of the replica set primary. <hostname>
和<port>
替换为副本集主副本的主机名和端口。Include any other parameters required for your deployment.包括部署所需的任何其他参数。
Issue the 在shell中发出rs.conf()
method in the shell and assign the result to a variable cfg
:rs.conf()
方法,并将结果分配给变量cfg
:
cfg = rs.conf();
The returned document contains a 返回的文档包含一个members
array, where each element in the array contains the configuration for a single replica set member.members
数组,其中数组中的每个元素都包含单个副本集成员的配置。
For the replica member to change to be non-voting, set its 要将副本成员更改为无投票,请将其votes
and priority
to 0
.votes
和priority
设置为0
。
cfg.members[n].votes = 0; cfg.members[n].priority = 0;
Replace 将n
with the array index position of the member to modify. n
替换为要修改的成员的数组索引位置。The members
array is zero-indexed, where the first element in the array has an index position of 0
.members
数组为零索引,其中数组中的第一个元素的索引位置为0。
The array index position of a member in the 成员数组中members
array is distinct from the members[n]._id
of a specific member. members
数组索引位置不同于特定成员的members[n]._id
。Do not use the 不要使用_id
to reference the array index position of any any member in members
._id
引用成员中任何members
的数组索引位置。
Use 使用rs.reconfig()
method to reconfigure the replica set with the updated replica set configuration document.rs.reconfig()
方法使用更新的副本集配置文档重新配置副本集。
rs.reconfig(cfg);
rs.reconfig()
shell method can force the current primary to step down, which causes an election. rs.reconfig()
shell方法可以强制当前的初选下台,从而导致选举。mongod
closes all client connections. mongod
关闭所有客户端连接。