mongodump
MongoDB
data restoration
database backup
data import

How to use the dumped data by mongodump?

Master System Design with Codemia

Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.

Introduction

mongodump does not produce plain JSON or CSV. It creates a MongoDB backup in BSON plus metadata files, and that backup is meant to be consumed primarily by mongorestore. If you are unsure what to do with a dump directory, the short answer is: restore it with the MongoDB Database Tools, or inspect it with bsondump if you only need to read it.

What mongodump Produces

A normal dump directory looks like this:

text
1dump/
2  mydb/
3    users.bson
4    users.metadata.json
5    orders.bson
6    orders.metadata.json

Each .bson file contains raw documents for one collection. The .metadata.json file stores index definitions and collection options.

This means the output is not intended for mongoimport. mongoimport expects JSON, CSV, or TSV. A mongodump backup should usually go into mongorestore.

Restore the Dump Into MongoDB

The most direct way to use the dumped data is to restore it into a running MongoDB server.

bash
mongorestore --db mydb /path/to/dump/mydb

That recreates collections from the BSON files inside the mydb directory.

If you want to replace existing data, add --drop.

bash
mongorestore --db mydb --drop /path/to/dump/mydb

Be careful with --drop: it removes matching collections before restoring them.

Restore the Whole Dump Directory

If the dump contains multiple databases, point mongorestore at the top-level dump directory.

bash
mongorestore /path/to/dump

MongoDB will restore each database subdirectory it finds.

This is the easiest path when you created the backup with a plain command such as:

bash
mongodump --out /path/to/dump

Restore Into a Different Database Name

Sometimes you want to load production data into a development database without overwriting the original name. Use namespace mapping.

bash
mongorestore   --nsFrom='mydb.*'   --nsTo='mydb_dev.*'   /path/to/dump/mydb

That restores the collections into mydb_dev instead of mydb.

Inspect the Backup Without Restoring It

If you just need to look at the data, use bsondump to convert BSON to JSON-like output.

bash
bsondump /path/to/dump/mydb/users.bson | head

You can also write it to a file:

bash
bsondump --outFile users.json /path/to/dump/mydb/users.bson

This is useful for debugging, but it is not the normal restore path for large backups.

Archive Mode and Streams

mongodump can also write an archive instead of a directory tree.

bash
mongodump --archive=backup.archive --gzip --db mydb

Restore it with the matching archive mode:

bash
mongorestore --archive=backup.archive --gzip

You can even stream between the two tools in pipelines for migrations, though for normal backup handling the directory or archive workflow is easier to reason about.

Credentials and Target Server

A dump file does not include the target connection automatically. You still need to tell mongorestore which server to load into.

bash
mongorestore   --uri='mongodb://localhost:27017'   --db mydb   /path/to/dump/mydb

For Atlas or authenticated clusters, use the appropriate connection string and credentials.

Common Pitfalls

A common mistake is trying to open .bson files directly in a text editor and expecting readable JSON. BSON is a binary format.

Another mistake is using mongoimport on mongodump output. That is the wrong tool chain. Use mongorestore for dumps and mongoimport for text-based exports.

Developers also forget that restoring into an existing database may create duplicates unless they use --drop or restore into a clean target.

Summary

  • 'mongodump output is intended for mongorestore, not mongoimport.'
  • The dump consists of .bson data files plus metadata files.
  • Restore one database by pointing mongorestore at that database directory.
  • Use bsondump when you need to inspect BSON without restoring it.
  • Be explicit about --drop, target database names, and connection details before restoring.

Course illustration
Course illustration

All Rights Reserved.