On this page本页内容
Hidden members are part of a replica set but cannot become primary and are invisible to client applications. 隐藏成员是副本集的一部分,但不能成为primary,并且对客户端应用程序不可见。Hidden members may vote in elections. 隐藏成员可以在选举中投票。For more information on hidden members and their uses, see Hidden Replica Set Members.有关隐藏成员及其使用的详细信息,请参阅隐藏副本集成员。
The most common use of hidden nodes is to support delayed members. 隐藏节点的最常见用法是支持延迟成员。If you only need to prevent a member from becoming primary, configure a priority 0 member.如果只需要防止成员成为主要成员,请配置优先级为0的成员。
If the 如果settings.chainingAllowed setting allows secondary members to sync from other secondaries, MongoDB by default prefers non-hidden members over hidden members when selecting a sync target. settings.chainingAllowed设置允许次要成员与其他次要成员同步,则在选择同步目标时,MongoDB默认情况下更喜欢非隐藏成员而不是隐藏成员。MongoDB will only choose hidden members as a last resort. MongoDB只能选择隐藏成员作为最后的选择。If you want a secondary to sync from a hidden member, use the 如果希望从隐藏成员同步辅助对象,请使用replSetSyncFrom database command to override the default sync target. replSetSyncFrom数据库命令覆盖默认同步目标。See the documentation for 在使用命令之前,请参阅replSetSyncFrom before using the command.replSetSyncFrom的文档。
To configure a secondary member as hidden, set its 要将次要成员配置为隐藏,请在其成员配置中将其members[n].priority value to 0 and set its members[n].hidden value to true in its member configuration:members[n].priority值设置为0,并将其members[n].hidden值设置为true:
{
  "_id" : <num>
  "host" : <hostname:port>,
  "priority" : 0,
  "hidden" : true
}
The following example hides the secondary member currently at the index 以下示例隐藏0 in the members array. members数组中当前索引0处的辅助成员。To configure a hidden member, use the following sequence of operations in a 要配置隐藏成员,请在连接到主会话的mongosh session that is connected to the primary, specifying the member to configure by its array index in the members array:mongosh会话中使用以下操作序列,通过members数组中的数组索引指定要配置的成员:
cfg = rs.conf() cfg.members[0].priority = 0 cfg.members[0].hidden = true rs.reconfig(cfg)
After re-configuring the set, this secondary member has a priority of 重新配置集合后,此次要成员的优先级为0 so that it cannot become primary and is hidden. 0,因此它不能成为主要成员并且被隐藏。The other members in the set will not advertise the hidden member in the 集合中的其他成员不会在hello command or db.hello() method output.hello命令或db.hello()方法输出中公布隐藏成员。
When updating the replica configuration object, access the replica set members in the 更新副本配置对象时,使用数组索引访问members array with the array index. members数组中的副本集成员。The array index begins with 数组索引以0. 0开头。Do not confuse this index value with the value of the 不要将此索引值与members[n]._id field in each document in the members array.members数组中每个文档中的members[n]._id字段的值混淆。
rs.reconfig() shell method can force the current primary to step down, which causes an election. rs.reconfig()shell方法可以强制当前的primary下台,从而导致选举。mongod closes all client connections. mongod关闭所有客户端连接。