Backup and Restore — MongoDB Technical Interview Questions & Answers

mongodump and mongorestore for database backups.

Backup and Restore

  • Simple meaning: mongodump copies data to files. mongorestore puts them back. These are CLI tools, not mongosh helpers.
  • How to use: mongodump --uri="mongodb://localhost:27017" --db=college --out=./backup then mongorestore --uri=... --db=college ./backup/college
  • Atlas: use the Atlas UI backup, or dump with the SRV URI.
  • Common mistake: copying data folders while mongod is running. Use dump/restore or Atlas backup.
  • Interview tip: mongodump/restore for binary backup. mongoexport for JSON/CSV.

Technical Interview Tip: dump/restore vs export/import (JSON).

Code Examples for Backup and Restore

Backup and Restore — working example

// Shell / terminal (not inside a filter query):
// mongodump --uri="mongodb://localhost:27017" --db=prep_pilot --out=./backup
// mongorestore --uri="mongodb://localhost:27017" --db=prep_pilot ./backup/prep_pilot

// Related query check after restore:
db.users.countDocuments({})
db.users.find().limit(2)

Backup and Restore — mongodump/mongorestore do binary backups; verify with count/find after restore.

How to Explain Backup and Restore to an Interviewer

How do you backup a database?

mongodump for that db Atlas backups in cloud