MongoDB Create Backup - MongoDB

How to create backup in Mongodb?

In this chapter, we will explain you how to create a backup in MongoDB.

Dump MongoDB Data

For creating a backup for database in MongoDB, use mongodump command. This command dumps the entire data of your server into the dump directory. There are many options which can be used to limit the amount of data or create backup of your remote server.


Basic syntax of mongodump command is as follows


Start mongod server. Suppose that your mongod server is running on the localhost and port 27017, open a command prompt and go to the bin directory of your mongodb instance and type the command mongodump

Consider the mycol collection has below data.

This command will connect to the server running at and port 27017 and back all data of the server to directory /bin/dump/. Below is the output of the command


Below is a list of available options which can be used with the mongodump command.




mongodump --host HOST_NAME --port PORT_NUMBER

This command backs up all databases of specified mongod instance.

mongodump --host --port 27017

mongodump --dbpath DB_PATH --out BACKUP_DIRECTORY

This command backs up only specified database at specified path.

mongodump --dbpath /data/db/ --out /data/backup/

mongodump --collection COLLECTION --db DB_NAME

This command backs up only specified collection of specified database.

mongodump --collection mycol --db test

Restore data

For restoring backup data MongoDB's, mongorestore command can be used. This command will restore all the data from the backup directory.


Basic syntax of mongorestore command is

Below is the output of the command


All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd Protection Status

MongoDB Topics