MongoDB - Create Backup

MongoDB - Create Backup : how to create a backup in MongoDB.

Dump MongoDB Data

To create backup of database in MongoDB, you should use mongodump command. This command will dump the entire data of your server into the dump directory.

There are many options available by which you can limit the amount of data or create backup of your remote server.


There are following basic syntax of mongodump command :


Start your mongod server. Assuming that your mongod server is running on the localhost and port 80,open a command prompt and go to the bin directory of your mongodb instance and type the command mongodump Consider the mycol collection has the following data.
The command will connect to the server running at and port 80 and back all data of the server to directory /bin/dump/.

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 commmand will backup all databases of specified mongod instance. mongodump --host tutorialspoint.com --port 27017
mongodump --dbpath DB_PATH --out BACKUP_DIRECTORY This command will backup only specified database at specified path. mongodump --dbpath /data/db/ --out /data/backup/
mongodump --collection COLLECTION --db DB_NAME This command will backup only specified collection of specified database. mongodump --collection mycol --db test

Restore data

To restore backup data MongoDB's mongorestore command is used. This command restores all of the data from the backup directory.


The basic syntax of mongorestore command is −



Welookups is optimized for learning.Copy right 2018 kumar aditya singh .
All Right Reserved and you agree to have read and accepted our term and condition.
All Rights Reserved.