🍃 MongoDB Tutorial

Export & Import a MongoDB Collection Using MongoDB Compass

Learn how to export a MongoDB collection to a file and import data into a new collection using the MongoDB Compass GUI — no command line required.

Export & Import with MongoDB Compass

MongoDB Compass, the official GUI, lets you export and import collections without touching the command line — handy when you want a quick one-off copy of your data or need to hand a collection's contents to someone non-technical.

Exporting a Collection

  1. Open the collection you want to export in Compass.
  2. Use the Export Collection action from the collection's menu.
  3. Compass lets you export the full collection (or a filtered subset) as JSON.

Importing a Collection

  1. Create or open the target collection (a brand-new, empty collection shows "This collection has no data").
  2. Click Import Data.
  3. Point it at a JSON or CSV file — Compass reads the file and inserts every document into the collection.

When to Use Compass vs. the CLI Tools

  • Compass is great for a quick, visual, one-off export/import — especially for someone who isn't comfortable with a terminal.
  • For repeatable, scriptable, or large-scale exports/imports, the command-line tools mongoexport/mongoimport (covered in the next lesson) are the better fit.

Common Errors & Troubleshooting

  • Import silently skipping documents — check Compass's import summary dialog; it typically reports how many documents succeeded vs. failed, often due to type mismatches with an existing schema validation rule.
  • Exported JSON not looking like valid MongoDB Extended JSON — Compass exports in MongoDB's Extended JSON format by default (preserving types like ObjectId/Date), which looks slightly different from plain JSON — don't hand-edit it into plain JSON if you plan to re-import it.
  • Large exports timing out or freezing the UI — for very large collections, prefer the command-line mongoexport (next lesson) over Compass's GUI export.

Key Takeaways

  • Compass's Export/Import Collection actions cover the exact same job as mongoexport/mongoimport, just with a GUI.
  • Both directions support JSON — Compass is the fastest way to move a collection's data without writing a single command.