# MongoServerError: CappedCollection: 无效的 oplog 条目，时间戳为 { ts: Timestamp(0, 0) }

- **ID:** `mongodb/capped-collection-invalid-oplog`
- **领域:** mongodb
- **类别:** data_error
- **验证级别:** ai_generated
- **修复率:** 85%

## 根因

oplog 包含一个时间戳为零的损坏条目，可能是由于磁盘写入错误或不当关机导致。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| MongoDB 5.0 | active | — | — |
| MongoDB 6.0 | active | — | — |
| MongoDB 7.0 | active | — | — |

## 解决方案

1. ```
   Restart the MongoDB instance with --repair to reconstruct the oplog: mongod --repair --dbpath /var/lib/mongodb
   ```
2. ```
   If the node is a secondary, resync from the primary by deleting the local database files and restarting: rm -rf /var/lib/mongodb/local/* && systemctl restart mongod
   ```
3. ```
   Use mongodump with --oplog to export the oplog, then drop and re-import to clean corrupted entries: mongodump --db local --collection oplog.rs --out /tmp/oplog_backup; mongo local --eval 'db.oplog.rs.drop()'; mongorestore --db local --collection oplog.rs /tmp/oplog_backup/local/oplog.rs.bson
   ```

## 无效尝试

- **** — The oplog is a special collection; manual deletion corrupts the storage engine state. (90% 失败率)
- **** — repairDatabase is not designed for internal system collections like oplog. (80% 失败率)
- **** — The corrupted entry remains in the oplog file after restart. (70% 失败率)
