How does MongoDB ensure data durability?
Instruction: Discuss the mechanisms MongoDB uses to ensure that data is safely stored and can be recovered in case of a failure.
Updated
Official answer
Durability depends on the storage engine, write concern and deployment configuration. WiredTiger journaling records changes for recovery after an unexpected shutdown. Its documented default journal commit interval is 100 milliseconds, not 60 seconds; checkpoint timing is a different mechanism. A journal is also different from the replication oplog.
A write concern controls when a write is acknowledged. Requesting journal acknowledgment and requesting replication acknowledgment address related but distinct failure scenarios. With the usual writeConcernMajorityJournalDefault setting enabled, majority acknowledgment waits for durable storage on the required members. Check the actual configuration instead of assuming every acknowledgment survives every failure.
A replica set maintains replicated copies and can elect a new primary. Replication is asynchronous and failover can interrupt writes. An arbiter votes but stores no data. Writes that have not reached the required durability/replication level can be rolled back after a primary change.
Set explicit requirements for acceptable data loss and recovery time, select suitable concerns and topology, and test failover and crash recovery in a controlled environment. Keep independent, recoverable backups: replication also propagates unwanted deletes and does not replace backup retention. Monitor replication health and restore tests as part of the durability design.
Related Questions
-
easy
-
easy
-
easy
-
medium
-
medium
-
medium