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→