Configure a Delayed Replica Set Member

To configure a delayed secondary member, set itsmembers[n].priority value to 0, itsmembers[n].hidden value to true, andits members[n].slaveDelay value to thenumber of seconds to delay.

Important

The length of the secondarymembers[n].slaveDelay mustfit within the window of the oplog. If the oplog is shorter thanthe members[n].slaveDelaywindow, the delayed member cannot successfully replicateoperations.

When you configure a delayed member, the delayapplies both to replication and to the member’s oplog. Fordetails on delayed members and their uses, seeDelayed Replica Set Members.

Example

The following example sets a 1-hour delay on a secondary membercurrently at the index 0 in themembers array. To set the delay, issuethe following sequence of operations in a mongo shellconnected to the primary:

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

After the replica set reconfigures, the delayed secondary member cannotbecome primary and is hidden from applications. Themembers[n].slaveDelay value delays bothreplication and the member’s oplog by 3600 seconds (1 hour).

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.