What is the difference between mongodump/mongorestore and mongoexport/mongoimport?

IntermediateConceptMongoDB
Answer

Short answer

mongodump/mongorestore create and restore binary BSON backups that preserve all data types and indexes — use them for backups. mongoexport/mongoimport read and write JSON or CSV — use them for data exchange with other tools, not for full backups, because some BSON type information can be lost.

Comparison

mongodump / mongorestore mongoexport / mongoimport
Format BSON (+ metadata) JSON / CSV
Preserves types (Decimal128, dates…) ✅ Partially (extended JSON)
Includes indexes ✅ ❌
Human-readable ❌ ✅
Use for Backups, migrations Exporting data for reports, importing CSV

Examples

mongodump --uri="$URI" --db shop --archive=shop.gz --gzip
mongorestore --uri="$URI" --archive=shop.gz --gzip

mongoexport --uri="$URI" --db shop --collection orders --query '{"status":"NEW"}' --out new_orders.json
mongoexport --uri="$URI" --db shop --collection customers --type=csv --fields name,email --out customers.csv
mongoimport --uri="$URI" --db shop --collection products --file products.json --jsonArray

What to say in the interview

"mongodump and mongorestore work in BSON, keep types and indexes and are for backups; mongoexport and mongoimport work in JSON or CSV for data exchange. For large production clusters we prefer snapshots or Atlas backups for consistency and speed."

All Databases (MySQL, PostgreSQL, MongoDB) questions Roadmap: MongoDB basics

More on MongoDB