How can you perform a backup in MongoDB?

Instruction: Describe the steps to perform a database backup in MongoDB.

Context: This question examines the candidate's knowledge of MongoDB's operational capabilities, specifically focusing on data durability and disaster recovery techniques.

Updated

Official answer

Choose a backup method for the deployment, required recovery point and recovery time. Managed snapshots/continuous backup or coordinated filesystem snapshots may be appropriate; logical mongodump/mongorestore has different size, time and consistency characteristics. Replication alone is not a backup because unwanted changes can replicate.

For a supported full replica-set logical dump, mongodump --oplog captures changes during the dump, and mongorestore --oplogReplay can replay that captured interval during restoration. The --oplog option is incompatible with limiting the dump by --db, --collection or --query. Connecting through mongos does not turn this into a consistent sharded-cluster backup procedure.

Do not describe one oplog-enabled dump as continuous point-in-time recovery to any later instant. Its captured interval is bounded. Use a documented backup system with the required retained history for broader point-in-time recovery, and follow the exact topology/version guidance.

Keep credentials out of command-line examples, shell history and repository files. Use supported protected authentication mechanisms, least-privilege backup/restore roles, encryption and separate retention/access controls.

Restore into an isolated target first. Check tool/server compatibility, indexes, document counts, representative queries and application invariants, then measure elapsed recovery time. A successful dump command alone does not establish recoverability. Record the backup's consistency scope, timestamp and verified restore result before relying on it.

MongoDB mongodump restrictions, mongorestore

Related Questions