QA
Senior LevelMongoDB & Mongoose

How do you calculate and resize the MongoDB Oplog Window to prevent replication lag breaks?

❓ Interview Prompt: Explain Oplog Window calculation, replication lag, resizing oplog (replSetResizeOplog), and avoiding secondary desync.

The Oplog Window represents the available replication time before old oplog entries are overwritten. Resizing the oplog prevents Secondaries falling out of sync during heavy write spikes.

Code Implementation Example

typescript
import mongoose from 'mongoose';

async function resizeOplog(sizeInMB: number) {
  const adminDb = mongoose.connection.db!.admin();
  await adminDb.command({ replSetResizeOplog: 1, size: sizeInMB });
}
💡Dynamically resizing the MongoDB Oplog window.
🎯 Interview Key Takeaway

Ensure the Oplog window covers at least 24 hours of write volume to prevent secondaries breaking during maintenance.

#Oplog Window#Replication Lag#Replica Sets#Senior
Back to all MongoDB & Mongoose Questions→

More MongoDB & Mongoose Interview Questions

Beginner LevelMongoDB & Mongoose

How does the MongoDB Aggregation Pipeline work? Explain $match, $group, $lookup, and $project.

Beginner LevelMongoDB & Mongoose

What is MongoDB and how does the BSON document data model work?

Beginner LevelMongoDB & Mongoose

What is the structure of a MongoDB ObjectId and how is it generated?