# MongoServerError: OplogTruncation: replication recovery failed due to missing oplog entries

- **ID:** `mongodb/oplog-truncation-during-recovery`
- **Domain:** mongodb
- **Category:** system_error
- **Verification:** ai_generated
- **Fix Rate:** 85%

## Root Cause

The oplog was truncated (e.g., due to replication lag or manual deletion) before a secondary could replay all entries, causing an irrecoverable gap in the replication stream.

## Workarounds

1. **Resync the secondary from scratch: stop the secondary, delete its data directory (e.g., rm -rf /data/db/*), then restart and let it perform an initial sync from the primary.** (95% success)
   ```
   Resync the secondary from scratch: stop the secondary, delete its data directory (e.g., rm -rf /data/db/*), then restart and let it perform an initial sync from the primary.
   ```
2. **If the primary still has the missing oplog entries (e.g., in a backup), restore them manually using mongorestore with --oplogReplay, then restart replication.** (70% success)
   ```
   If the primary still has the missing oplog entries (e.g., in a backup), restore them manually using mongorestore with --oplogReplay, then restart replication.
   ```

## Dead Ends

- **** — Increasing oplog size (e.g., via --oplogSizeMB) prevents future truncation but does not recover the lost entries; the secondary remains stuck. (95% fail)
- **** — Restarting the secondary node only re-attempts the same recovery, which fails again since the oplog gap persists. (90% fail)
