Search code examples
mongodbreplicationdatabase-replicationmongodb-cluster

MongoDB Replication Info Results


I want to understand the following:

  1. First-Third execution of db.printSlaveReplicationInfo() results to “0 secs (0 hrs) behind the primary”
  2. Fourth execution of db.printSlaveReplicationInfo() results to “4 secs (0 hrs) behind the primary”
  3. Fifth and Sixth execution of db.printSlaveReplicationInfo() results to “2 secs (0 hrs) behind the primary”
  4. Seventh-Tenth execution of db.printSlaveReplicationInfo() results to “0 secs (0 hrs) behind the primary”

Why is the lag always changing even if there are no changes or queries executed?


Solution

  • There are always writes being executed.

    If nothing else has been written for 10 seconds, the primary node will write a no-op into the oplog to make sure replication is functioning.