Replica Set Secondary Members

A secondary maintains a copy of the primary’s dataset. To replicate data, a secondary applies operations from theprimary’s oplog to its own data setin an asynchronous process. [1] A replica set can have one or moresecondaries.

The following three-member replica set has two secondarymembers. The secondaries replicate the primary’s oplog and applythe operations to their data sets.

Diagram of a 3 member replica set that consists of a primary and two secondaries.

Although clients cannot write data to secondaries, clients can readdata from secondary members. See Read Preference for moreinformation on how clients direct read operations to replica sets.

A secondary can become a primary.If the current primary becomes unavailable, the replica setholds an election to choose which of the secondariesbecomes the new primary.

In the following three-member replica set, the primary becomes unavailable.This triggers an election where one of the remainingsecondaries becomes the new primary.

Diagram of an election of a new primary. In a three member replica set with two secondaries, the primary becomes unreachable. The loss of a primary triggers an election where one of the secondaries becomes the new primary

SeeReplica Set Elections for more details.

You can configure a secondary member for a specific purpose. You canconfigure a secondary to:

  • Prevent it from becoming a primary in an election, which allows it toreside in a secondary data center or to serve as a cold standby. SeePriority 0 Replica Set Members.
  • Prevent applications from reading from it, which allows it to run applicationsthat require separation from normal traffic. SeeHidden Replica Set Members.
  • Keep a running “historical” snapshot for use in recovery fromcertain errors, such as unintentionally deleted databases. SeeDelayed Replica Set Members.
[1]Starting in version 4.2 (also available starting in 4.0.6), secondary members of a replica set nowlog oplog entries that take longer than the slowoperation threshold to apply. These slow oplog messages are loggedfor the secondaries in the diagnostic log under the REPL component with the text appliedop: <oplog entry> took <num>ms. These slow oplog entries dependonly on the slow operation threshold. They do not depend on the loglevels (either at the system or component level), or the profilinglevel, or the slow operation sample rate. The profiler does notcapture slow oplog entries.