liveBook · Manning

Follower node

As explained in MongoDB 8.0 in Action, Third Edition

A secondary member is a replica set member that replicates data from the primary and can serve configured read operations.

A follower node is a secondary member of a MongoDB replica set. The primary accepts writes; a secondary keeps a replica of the data and can serve configured read operations. A secondary is also eligible to vote in a primary election. Unlike a secondary, an arbiter can vote but does not store a data replica. section 9.1.1

Replication runs through the oplog, an ordered history of logical writes. The primary records successful, data-changing operations and streams them to secondaries. Each secondary applies those operations asynchronously and maintains its own copy of local.oplog.rs. Because application is asynchronous, check replication lag rather than assuming a secondary is current. section 9.1.3

Inspect a secondary in mongosh:

  • Run rs.status() or db.adminCommand("replSetGetStatus") to identify members whose state is SECONDARY. State 2 means the member is replicating; states such as STARTUP2 and ROLLBACK indicate different conditions. section 9.1.1
  • Run db.printSecondaryReplicationInfo() to inspect each reported member’s syncedTo time and replLag relative to the primary. section 9.1.3
  • For member configuration, use rs.config() or db.adminCommand("replSetGetConfig") to inspect fields such as hidden, priority, and votes. The latter command is noted as available only on M10 clusters and larger. section 9.1.1
Listing 9.1 Output of the replSetGetStatus command
db.adminCommand("replSetGetStatus").members.map((m) =>
➥({ _id: m._id, name: m.name, state: m.state, stateStr: m.stateStr }))
[
 {
  _id: 0,
  name: 'ac-5dhjxpf-shard-00-00.fpomkke.mongodb.net:27017'
  state: 2,
  stateStr: 'SECONDARY'
 },
 {
  _id: 1,
  name: 'ac-5dhjxpf-shard-00-01.fpomkke.mongodb.net:27017'
  state: 1,
  stateStr: 'PRIMARY'
 },
 {
  _id: 2,
  name: 'ac-5dhjxpf-shard-00-02.fpomkke.mongodb.net:27017'
  state: 2,
  stateStr: 'SECONDARY'
 }
]

The status output shows one PRIMARY and two members in state 2, SECONDARY; use the state alongside the member name to identify each follower. section 9.1.1

Listing 9.6 Output of the db.printSecondaryReplicationInfo() command
db.printSecondaryReplicationInfo()
source: ac-5dhjxpf-shard-00-00.fpomkke.mongodb.net:27017
{
  syncedTo: 'Wed Mar 27 2024 18:21:52 GMT+0000
➥(Coordinated Universal Time)',
  replLag: '0 secs (0 hrs) behind the primary '
}
---
source: ac-5dhjxpf-shard-00-01.fpomkke.mongodb.net:27017
{
  syncedTo: 'Wed Mar 27 2024 18:21:53 GMT+0000
➥(Coordinated Universal Time)',
  replLag: '10 secs (0 hrs) behind the primary '
}

The replication report shows syncedTo timestamps and lag values, including a member reported as 10 seconds behind the primary. section 9.1.3

How MongoDB 8.0 in Action, Third Edition covers it

How deep it goes
Explains member states and asynchronous oplog application, then shows status and lag inspection without a failure-recovery procedure.
Examples
Shows a replica set with one primary and two secondaries, plus sample oplog entries and a replication-lag report.
What it assumes
Introduces member-state meanings and the oplog while using MongoDB replica-set terminology and mongosh commands.
What you can do after
Diagnose/debug with mongosh status and replication-info commands to identify secondary members and inspect their reported lag.
How it connects
Connects secondaries to replica sets, primary elections, arbiters, oplogs, and replication lag.

Also explained in

Compare how 3 books explain follower node →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of MongoDB 8.0 in Action, Third Edition. The section links point to the parts of the book it draws on.