MongoDB: how to backup & restore database data?

MongoDB: how to backup & restore database data?

  • 2020-11-30

For lazy people, use mongodump, it's faster:

1
mongodump -d <database_name> -o <directory_backup>

And to "restore/import" it (from directory_backup/dump/):

1
mongorestore -d <database_name> <directory_backup>

This way, you don't need to deal with all collections individually. Just specify the database.

Note that I would recommend against using mongodump/mongorestore for big data storages. It is very slow and once you get past 10/20GB of data it can take hours to restore.

Ref: https://stackoverflow.com/a/16605781/13647950