Home >>MongoDB Tutorial >MongoDB Create Backup

MongoDB Create Backup

How to take Dump(Backup) MongoDB Data

You can use the MongoDB command to build a backup of the MongoDB database. This command will dump your server's entire data into the dump directory. There are several ways to limit the amount of data or to build backup for your remote server.


The basic syntax of mongodump command is as follows −



Get the Mongod server started. If your mongod server is running on localhost and port 27017, open a prompt for the command and go to your mongoDB instance's bin directory and enter the mongoDB command.

Consider the following information is available in mycol collection.


Following is a list of available options that can be used with the mongodump command.

Syntax Description Example
mongodump --host HOST_NAME --port PORT_NUMBER This command will back up all the databases of the Mongod instance you mentioned. mongodump --host tutorialspoint.com --port 27017
mongodump --dbpath DB_PATH --out BACKUP_DIRECTORY This command will only backup the specified database to the path you specified. mongodump --dbpath /data/db/ --out /data/backup/
mongodump --collection COLLECTION --db DB_NAME This command only backs up the stated database collection. mongodump --collection mycol --db test

Restore data

MongoDB's Mongorestore command is used to restore backup data. This command restores all of the backup directory 's data.


The basic syntax of mongorestore command is −


No Sidebar ads