# MongoServerError：OplogTruncation：由于缺少 oplog 条目，复制恢复失败

- **ID:** `mongodb/oplog-truncation-during-recovery`
- **领域:** mongodb
- **类别:** system_error
- **验证级别:** ai_generated
- **修复率:** 85%

## 根因

由于复制延迟或手动删除，oplog 在辅助节点重放所有条目之前被截断，导致复制流中出现无法恢复的间隙。

## 解决方案

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.
   ```
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.
   ```

## 无效尝试

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