How to restore a MongoDb backup

If you need to know how to restore a MongoDb backup generated by mongodump, as we saw in the post about scheduling backups using cron, just follow reading, it’s very easy.

How to restore a MongoDb backup

Following the previous example, you should have 2 files per collection: one .bson file and one .json file.

First, get the container folder of your backup folder.

cd /the/path/to/backup-folder 
cd ../

If you want to restore all the collections, just run:

mongorestore -d my_database_name backup-folder/

Please note you should change your my_database_name and the backup-folder name.

If you want to restore only one collection, just run:

mongorestore -d my_database_name -c my_collection_name backup-folder/my_collection_name.bson

Remember to change my_database_name, my_collection_name and the path to the collection.bson file.

You can read more about mongorestore on the official documentation.

It just works, hope it helps!

Leave a comment with your experience or doubts 🙂

David Burgos

Read more posts by this author.