What is the oplog in MongoDB?

IntermediateConceptMongoDB
Answer

Short answer

The oplog (operations log) is a special capped collection (local.oplog.rs) on each replica set member that records every write operation in order. Secondaries copy and replay it from the primary to stay in sync. Its size defines the oplog window — how long a secondary can be offline and still catch up.

Check it

rs.printReplicationInfo()
// configured oplog size: 10240MB
// log length start to end: 48 hours   ← the oplog window
rs.printSecondaryReplicationInfo()    // how far behind each secondary is

Why it matters

  • If a secondary is down longer than the oplog window, it falls off the end and needs a full resync.
  • Big bulk writes can shrink the window quickly.
  • Change streams and some backup/CDC tools read from the oplog.

Resize (MongoDB 4.0+)

db.adminCommand({ replSetResizeOplog: 1, size: 20480 })   // MB

What to say in the interview

"The oplog is the ordered log of writes that secondaries replay. Its window determines how long a member can be down and still catch up, so I size it for maintenance windows and peak write volumes and monitor replication lag."

All Databases (MySQL, PostgreSQL, MongoDB) questions Roadmap: MongoDB basics

More on MongoDB