MongoDB Database Backup And Restore

In this article, I will explain how we create a backup and restore the database in MongoDB.

Steps required to create backup of mongodb database,

Step 1

Open command prompt by pressing window + R and changing directory to the location in which MongoDB server is saved.

Go to MongoDB folder >Server >bin folder and copy the folder address. In my system folder location C:\Program Files\MongoDB\Server\4.0\bin

 
 
Change the directory Cd C:\Program Files\MongoDB\Server\4.0\bin and press enter.

Now enter mongod and press enter button and check the cmd screen

Now create a folder at any location in your system in which you want to create a backup. In my case I create a folder in desktop and rename it as Backup

Now back to cmd and enter mongodump --out <Backup folder location address> Now Press Enter,

mongodump --out C:\Users\vinay\Desktop\Backup
 
 
 
Now Press Enter and open Backup folder and a backup of all databases is created.

Note
To create a backup of a particular database backup use mongodump --<db database name> --out <folder location>

mongodump --db abc --out C:\Users\vinay\Desktop\Backup
 

Now open Backup folder backup of abc  and database is created

Restore database - First delete abc database

In MongoDB for restoring database use mongorestore .

Syntax

mongorestore --<database name > <folder location>
mongorestore --db abc C:\Users\vinay\Desktop\Backup\abc
 
Now press enter

Now open Robo 3T and check if abc database is restored.

Summary

In this article we learned how to  create a database backup and restore it  in MongoDB.
Next Recommended Reading Create Index in MongoDb