Home >>MongoDB Tutorial >MongoDB Create Backup
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.
Syntax
The basic syntax of mongodump command is as follows −
>mongodump
Example
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.
>mongodump
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 |
MongoDB's Mongorestore command is used to restore backup data. This command restores all of the backup directory 's data.
Syntax
The basic syntax of mongorestore command is −
>mongorestore