Tips, Tricks & Hacks

How To: Drop, Backup and Restore a MongoDB database

A quick note to self and other alike on how to drop a database, backup a database and restore a database in MongoDB.

Drop Database

Just use the command db.dropDatabase() from the mongo command line client.

use db;

Backup Database

To backup a local mongo databse Use the command line utility mongodump.

mongodump -d dbname

This would create a folder “dump” containing the dbname folder further containing all collections. Use this “dbname” folder to restore database.

Restore Database

To restore a backup, taken earlier using mongodump, use the command mongorestore.

mongorestore -d dbname Path_of_dump_folder

Where path of dump folder would be path till “dbname” folder from the mongodump example above.

For More detailed reference documentation on the subject, refer to the mongoDB documentation here and here  .


No comments for “How To: Drop, Backup and Restore a MongoDB database”