In MongoDB, the oplog is a special collection used in replication. What is its main purpose?
Think about how changes are shared between primary and secondary nodes.
The oplog (operation log) records all write operations on the primary node. Secondary nodes read this log to apply the same changes and stay synchronized.
Consider this MongoDB query on the oplog collection:
db.oplog.rs.find({op: 'i'}).count()What does this query return?
Look at the filter {op: 'i'} and what 'i' stands for in oplog entries.
In the oplog, the field 'op' indicates the operation type. 'i' means insert, so the query counts all insert operations.
Which option contains a syntax error when querying the oplog for update operations?
db.oplog.rs.find({op: 'u'})Check the syntax for specifying query filters in MongoDB.
In MongoDB queries, filters use colon ':' to assign values, not '='. Option C uses '=' which is invalid syntax.
You have a busy MongoDB replica set and want to optimize the oplog size to avoid losing operations during replication lag. Which approach is best?
Think about how oplog size affects replication lag tolerance.
A larger oplog can store more operations, allowing secondaries more time to catch up if they fall behind. Smaller oplogs risk losing operations if secondaries lag too much.
A secondary node in a MongoDB replica set is not applying oplog entries and shows this error: Rollback due to missing oplog entries. What is the most likely cause?
Consider what happens if a secondary falls behind too much.
If a secondary falls behind longer than the oplog window (the time span oplog entries are kept), it cannot find the missing operations to catch up and must rollback or resync.