Backup and Restore MongoDB

By | October 29, 2016

Backup MongoDB Database

Backing up all MongoDB databases can be accomplished by running the following command.


This will create a “dump” directory in the current working directory containing all available databases. Here is an example of a single database requiring user credentials being backed up.

mongodump -u username -p password -d mydatabase

The -p parameter without a password argument will prompt for the user password.

Restore MongoDB Database

Previously backed up databases can be restored by specifying the path to the existing “dump” directory.

mongorestore ./dump

A single database backup may need to be restored over an existing database and the existing collections automatically replaced. Use the –drop parameter with caution.

mongorestore --drop ./dump/my_database

Third-party Tools

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.