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 replSetSyncFrom
before using the command.
See also
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:
- {
- "_id" : <num>
- "host" : <hostname:port>,
- "priority" : 0,
- "hidden" : true
- }
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:
- 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 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.