Restore a MongoDB Logical Backup

April 18, 2018
Author
Tim Vaillancourt
Share this Post:

MongoDB restore backup
In this article, we explain how to restore a MongoDB logical backup performed via mongodump to a mongod instance.

MongoDB logical backups require the mongorestore tool to restore data. This article focuses on that process.

Note: Percona provides mongodb_consistent_backup, which wraps mongodump to provide cluster-wide consistency. Backups created with it can be restored using the same steps as standard mongodump backups.

Mongorestore Command Flags

–host / –port (–user / –password)

Required, even for localhost. Include authentication flags if enabled.

–drop

Almost always required. Drops collections before restoring to avoid duplicate key errors.

–oplogReplay

Almost always required. Replays oplog entries for consistency. Look for oplog.bson in the dump directory.

–dir

Required. Path to the mongodump data.

–gzip

Optional. Required if the backup used compression (.bson.gz files).

–numParallelCollections=<number>

Optional. Controls parallelism for restoring collections. Default is 4 threads.

Steps

  1. (Optional) Extract the backup if archived:

    This extracts to /opt/mongodb/backup/testbackup/…/dump

  2. Verify you are restoring the correct backup to the correct host:

    • Check replica set naming in backup directories
    • Restore to PRIMARY in replica sets
    • Ensure majority availability for writes
  3. Run mongorestore:

    • Use -vvv for verbose debugging if needed
  4. Verify completion:

    • Look for replaying oplog
    • Look for done

Notes

For sharded environments:

  • --oplog is not supported
  • mongodump uses primaries (not ideal for production)
  • Consider using mongodb_consistent_backup for safer backups

Careers

If MongoDB topics interest you, Percona is hiring:

Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments

Far
Enough.

Said no pioneer ever.
MySQL, PostgreSQL, InnoDB, MariaDB, MongoDB and Kubernetes are trademarks for their respective owners.
© 2026 Percona All Rights Reserved