Skip to main content

Backup & Restore Data

With these commands, entire database instances as well as individual collections can be backed up and restored correctly. There are several options for the level at which this can be done.

Backup

The following command backups the entire instance of MongoDB with all databases and collections including their contents.

mongodump --host="<yourmognodbinstance>:<yourmongodbport>" --port=<yourmongodbport> -o "<youroutputpatchforbackupfiles>"

If you only want to back up a single database, you can add the name to the path.

mongodump --host="<yourmognodbinstance>:<yourmongodbport>/<yourdatabasename>" --port=<yourmongodbport> -o "<youroutputpatchforbackupfiles>"

Restore

Import data to Collection

mongorestore -d <yourdatabasename> -c <yourcollectionname> <yourpathtosinglebsonfile>

Restore single Collection

mongorestore --drop -d <yourdatabasename> -c <yourcollectionname> "<yourpathtosinglebsonfile>"

Restore complete Database

mongorestore -d <yourdatabasename> "<yourpathtodatabasebackupfolder>"

// SAME FOR WINDOWS
.\mongorestore.exe --uri "mongodb://<yourmognodbinstance>:<yourmongodbport>" -d <yourdatabasename> "<yourpathtodatabasebackupfolder>"