mongoimport and mongoexport — MongoDB Technical Interview Questions & Answers
Bulk-loading and exporting JSON/CSV data.
mongoimport and mongoexport
- Simple meaning: mongoexport writes JSON/CSV files. mongoimport loads them. Good for spreadsheets and sharing class data.
- How to use: mongoexport --uri=... --db=college --collection=students --out=students.json then mongoimport --file=students.json --jsonArray if needed.
- Common mistake: importing JSON array without --jsonArray. Mixing this with mongodump (dump is BSON backup).
- Interview tip: export/import = readable JSON/CSV. dump/restore = binary backup.
Technical Interview Tip: export/import vs dump/restore.
Code Examples for mongoimport and mongoexport
mongoimport and mongoexport — working example
// Terminal:
// mongoexport --uri="mongodb://localhost:27017" --db=prep_pilot --collection=users --out=users.json
// mongoimport --uri="mongodb://localhost:27017" --db=prep_pilot --collection=users --file=users.json --jsonArray
db.users.find().limit(2)mongoimport and mongoexport — mongoexport/mongoimport move JSON/CSV; use mongodump for full binary backups.
How to Explain mongoimport and mongoexport to an Interviewer
mongoexport vs mongodump?
JSON/CSV vs binary backup