mongodb
data_error
ai_generated
true
MongoServerError: CappedCollection: invalid oplog entry with timestamp { ts: Timestamp(0, 0) }
ID: mongodb/capped-collection-invalid-oplog
85%Fix Rate
82%Confidence
1Evidence
2024-01-20First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| MongoDB 5.0 | active | — | — | — |
| MongoDB 6.0 | active | — | — | — |
| MongoDB 7.0 | active | — | — | — |
Root Cause
The oplog contains a corrupted entry with a zero timestamp, likely due to a disk write error or improper shutdown.
generic中文
oplog 包含一个时间戳为零的损坏条目,可能是由于磁盘写入错误或不当关机导致。
Official Documentation
https://www.mongodb.com/docs/manual/core/capped-collections/Workarounds
-
80% success Restart the MongoDB instance with --repair to reconstruct the oplog: mongod --repair --dbpath /var/lib/mongodb
Restart the MongoDB instance with --repair to reconstruct the oplog: mongod --repair --dbpath /var/lib/mongodb
-
95% success 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
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
-
85% success 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
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
中文步骤
Restart the MongoDB instance with --repair to reconstruct the oplog: mongod --repair --dbpath /var/lib/mongodb
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
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
Dead Ends
Common approaches that don't work:
-
90% fail
The oplog is a special collection; manual deletion corrupts the storage engine state.
-
80% fail
repairDatabase is not designed for internal system collections like oplog.
-
70% fail
The corrupted entry remains in the oplog file after restart.