Explain how MongoDB handles data recovery in the event of a crash.
Instruction: Discuss MongoDB's data recovery mechanisms and how they ensure data durability.
Updated
Official answer
For WiredTiger, a valid checkpoint provides a consistent recovery point in the data files, and journal replay recovers durable changes after that checkpoint. A crash between checkpoints can therefore be recovered without rebuilding the database from scratch, provided the necessary files remain intact.
This does not mean every recently acknowledged write survives every failure. The result depends on journal/write-concern settings, replication acknowledgment and the failure itself. Storage loss or corruption may require a healthy replica or backup rather than local journal replay.
In a replica set, eligible members can elect a new primary when a voting majority is available. Writes may pause during failover, and insufficiently replicated writes can roll back. The application must handle connection changes and ambiguous write outcomes.
Define recovery point and recovery time objectives as targets. Then measure actual data loss and time to restore service in controlled drills; naming RPO/RTO is not evidence the targets were met. Validate representative data and application invariants after recovery.
Maintain tested independent backups and documented restore/failover procedures. Avoid destructive repair or forced reconfiguration as routine first steps when a safer healthy-copy recovery path exists.