How to Fix MongoDB Error 120 (OplogStartMissing)
You see mongodb error 120, known as OplogStartMissing, when a replica loses its starting log point. You fix it by syncing the lagging node from a healthy data source or snapshot. Every replica set tracks data changes in a rolling operation log. Secondary nodes read this log to copy updates from the primary node. When the log fills up, the database overwrites the oldest entries first. If a secondary node stops reading for too long, its last known point disappears. The node then fails with code 1
Your coding agents run with your access.
Claude Code reaches prod with a developer's credentials, and approval prompts get clicked through. hoop.dev checks every query, masks sensitive data, and holds risky changes for a human.
You see mongodb error 120, known as OplogStartMissing, when a replica loses its starting log point. You fix it by syncing the lagging node from a healthy data source or snapshot.
Every replica set tracks data changes in a rolling operation log. Secondary nodes read this log to copy updates from the primary node. When the log fills up, the database overwrites the oldest entries first. If a secondary node stops reading for too long, its last known point disappears. The node then fails with code 120 because it cannot resume where it left off.
What causes mongodb error 120 in replica sets
Several cluster events can push a secondary node behind the active log window. High write volume is the most common cause in busy production clusters. Bulk imports or large batch updates can cycle through the log window very fast. If the log space is too small for the write rate, older records vanish.
Network splits and node downtime also trigger OplogStartMissing during recovery. A secondary node might go offline for disk repairs or host reboots. While that node is down, the primary node keeps taking new writes. When the offline node comes back, its saved log timestamp is no longer present.
Slow disk reads on a secondary node can cause the same problem over time. If a replica cannot apply writes as fast as the primary, replication lag grows. Once the lag exceeds the log retention window, the database throws code 120. Change stream readers can also hit this error if they pause and resume using an expired token.
How to diagnose and fix OplogStartMissing safely
Start your check by viewing the replication status and log window on the cluster. You do not need full write rights to inspect node health. MongoDB uses role-based authorization to grant actions on specific databases or collections. The built-in read role grants actions like find, dbStats, collStats, and changeStream on non-system collections. Granting least-privilege read access lets engineers check lag metrics without risking accidental data changes.
Once you confirm Which secondary node hit code 120, you must resync its data. You can restore the node from a recent backup snapshot of a healthy member. You can also run a fresh initial sync if network bandwidth and load allow it. Restoring from a snapshot is often faster for large datasets and reduces primary load.
MongoDB Authentication & Authorization + End-to-End Encryption: architecture patterns and best practices
Continue reading? Get the full guide.
Free. No spam. Unsubscribe anytime.
After the node catches up, prevent the error from coming back. Check the time span covered by your current operation log during peak write hours. Increase the log size so it holds enough hours of writes to survive maintenance windows. Schedule large batch writes during low traffic periods or break them into smaller chunks. If an app change stream hit the error, restart the stream without the old token and read current state first.
How to protect production data during error recovery
Fixing replication errors often requires engineers to inspect live cluster state and run diagnostic queries. Giving team members broad database roles during an outage creates security and compliance risks. The readWrite role includes actions like insert, update, remove, and dropCollection. You should restrict these destructive actions when an engineer only needs to check replication health.
Teams should also protect sensitive fields when querying collections to verify data sync. Dynamic data masking rewrites matched fields like emails, phone numbers, card numbers, and national IDs in query results. This approach lets operators verify collection state while keeping regulated personal data private.
Add command guardrails and field masking beside MongoDB
Collection roles and IP rules control who connects to MongoDB. Yet an active client or agent session can still run a pipeline that writes data or reads raw personal fields. In practice, hoop.dev sits inline in the wire protocol beside your database as a sidecar for your MongoDB. For every command an agent or human sends in production, hoop.dev decides to pass, mask, block, or escalate it for review.
Using hoop.dev MongoDB controls, guardrails refuse banned commands before they run or hold risky calls for approval, and data masking rewrites matched fields in returned documents in memory. Furthermore, hoop.dev holds SOC 2 Type II, is MIT licensed, and generates evidence for GDPR, HIPAA, and PCI DSS programs. View the project on GitHub.
Frequently asked questions
What does OplogStartMissing mean in MongoDB?
OplogStartMissing is the official name for error code 120 in MongoDB. It means the starting operation log entry requested by a replica or reader no longer exists.
Can I fix mongodb error 120 without a full resync?
No, once the needed log entry is overwritten, the node cannot catch up by log replay. You must restore the node from a recent backup snapshot or run an initial sync.
How do I stop code 120 from happening again?
Size your operation log to hold many hours of peak write traffic. Monitor replication lag alerts so your team can fix slow nodes before the log rolls over.
Related guides
In this post