Mongodb The OpLog Explained

As I watch the mongodb mailing list and the IRC channel I have come to understand that there is a lack of understanding about the mongodb oplog. While most of this information can be found in the mongodb online documentation I figured I’d make a blog about it to make it more clear for some people.

What The Heck Is An OpLog

From the mongodb website “Replication uses an operation log (“oplog”) to store write operations. These operations replay asynchronously on other nodes.” Now you must be asking your self what the heck does that mean. Basically the OpLog is a collection (a collection can be thought of a table in a database) of write operations (updates, deletes, inserts) which are stored in order of operation, this allows other members of the replica set (cluster) to apply these changes to the local copy of their database.

How Big Is The OpLog?

This is a very good question. The OpLog is a capped collection which means it only stores a certain number of records after that number is reached the oldest record is dropped from the OpLog. By default 5% of the partition where the dbpath lives is reserved for the oplog, but this is a configurable option.

--oplogSize 

Querying The OpLog

A common question that I see in the mongodb forums is “can I query the mongodb oplog” and the answer is most certainly yes. The oplog can be queried like any other collection. From the shell here is an example of how to query the oplog:

MongoDB shell version: 2.0.4
connecting to: mongodb:27017/test
PRIMARY> use local
PRIMARY> db.oplog.rs.find()

This will show you all of the items in the oplog.rs collection.

5 Comments

Add a Comment

Your email address will not be published. Required fields are marked *