Configure a Hidden Replica Set Member

Hidden members are part of a replica set but cannot becomeprimary and are invisible to client applications. Hidden membersmay vote in elections. Formore information on hidden members and their uses, seeHidden Replica Set Members.

Considerations

The most common use of hidden nodes is to support delayedmembers. If you only need to prevent a member frombecoming primary, configure a priority 0 member.

If the settings.chainingAllowed settingallows secondary members to sync from other secondaries, MongoDB bydefault prefers non-hidden members over hidden members when selectinga sync target. MongoDB will only choose hidden members as a lastresort. If you want a secondary to sync from a hidden member, use thereplSetSyncFrom database command to override the defaultsync target. See the documentation for replSetSyncFrombefore using the command.

See also

Manage Chained Replication

Examples

Member Configuration Document

To configure a secondary member as hidden, set itsmembers[n].priority value to 0 andset its members[n].hidden value totrue in its member configuration:

  1. {
  2. "_id" : <num>
  3. "host" : <hostname:port>,
  4. "priority" : 0,
  5. "hidden" : true
  6. }

Configuration Procedure

The following example hides the secondary member currently at the index0 in the members array. To configurea hidden member, use the following sequence of operations in amongo shell connected to the primary, specifying the memberto configure by its array index in themembers array:

  1. cfg = rs.conf()
  2. cfg.members[0].priority = 0
  3. cfg.members[0].hidden = true
  4. rs.reconfig(cfg)

After re-configuring the set, this secondary member has a priority of0 so that it cannot become primary and is hidden. The other membersin the set will not advertise the hidden member in theisMaster or db.isMaster() output.

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.