Oplogs in MongoDB

Chandan Gr
2 min readJun 1, 2021

In this blog let us have a basic idea on…
What are Oplogs? How they are used in replica sets?

What are Oplogs? How they are used in replica sets?

  • The oplog(operations log) is a capped collection.
    Now, what is capped collection?? — A fixed-sized collection that automatically overwrites its oldest entries when it reaches its maximum size.
  • All replica set members have their own oplog.
  • When MongoDB does DB operations on the primary node, it records these operations on the primary’s node oplog.
    Once any new operations are recorded in primary’s node oplog, the secondary members then copy those operations and apply those operations in their oplog in an asynchronous process. In this way, it maintains the same data in all the replica members.
  • Oplog size: Once you have started a replica set member for the first time, it takes the default size as shown below:
  • Change Oplog size: Once you have started a replica set member for the first time, use the replSetResizeOplog administrative command to change the oplog size.
db.adminCommand(
{
replSetResizeOplog: <int>,
}
)
  • View Oplog status: To view oplog status..you can type rs.printReplicationInfo() and it outputs like below
configured oplog size:   192MB
log length start to end: 65422secs (18.17hrs)
oplog first event time: Mon Jun 23 2014 17:47:18 GMT-0400 (EDT)
oplog last event time: Tue Jun 24 2014 11:57:40 GMT-0400 (EDT)
now: Thu Jun 26 2014 14:24:39 GMT-0400 (EDT)

Thank You…

--

--