MongoDB Backup and Restore

Create a Backup in MongoDB

To create a backup of your databases in MongoDB, we'll use the mongodump command. This command will dump your selected databases into the specified folder used by --out command.

Example of mongodump

mongodump --host <host> --port <port> 
	--username <user> --password "<pass>" 
	--out <path>/mongodump-<date>

Restore data in MongoDB

To restore a backup of your databases in MongoDB, we'll use the mongorestore command. This command will take your already dumped folder and insert it into your database.

Example of mongorestore

mongorestore --host <host> --port <port> 
	--username <user> --password "<pass>" 
	<path>/mongodump-<date>

You can also use mongoimport and mongoexport, but they should be avoided for full instance production backups. They do not reliably preserve all rich BSON data types, because JSON can only represent a subset of the types supported by BSON. Use mongodump and mongorestore as described in MongoDB Backup Methods for this kind of functionality.