inchirags@gmail.com Chirag's MongoDB DBA Tutorial https://www.chirags.in
*****************************************************************************************
*Backup and Restore MongoDB in Windows using both the command line and MongoDB Compass*
*****************************************************************************************
YouTube Video:
MongoDB Database server:
Server IP: 192.168.224.133
Steps:
1. Install MongoDB Tools
First, ensure that you have the MongoDB Database Tools installed, which includes mongodump and mongorestore:
Download MongoDB Tools:
Go to the MongoDB Tools download page.
https://www.mongodb.com/try/download/database-tools
Choose your operating system (Windows), download the ZIP file, and unzip it to a folder of your choice.
Add MongoDB Tools to Path (optional, but recommended for easier access):
Open Environment Variables settings in Windows.
Add the path to the folder where MongoDB Tools are installed (usually something like C:\mongodb-database-tools-windows-x86_64-xxxx\bin) to your PATH variable.
2. Create a Database
On the home screen, click "Create Database".
In the dialog box:
Database Name: Enter a name, e.g., mydatabase.
Collection Name: Enter a collection name, e.g., users.
Click "Create Database".
3. Add Collections
In the left-hand panel, select your newly created database (mydatabase).
Click the "Add Collection" button.
Enter a collection name, e.g., orders, and click "Create".
4. Insert Data into Collections
Insert data into the users collection:
Select the users collection.
Click "Insert Document".
Add data in JSON format. For example:
{
"name": "Chirag Mahto",
"email": "inchirags@gmail.com",
"age": 35
}
Click "Insert".
Repeat this step to add more documents.
Insert data into the orders collection:
5. Select the orders collection.
Click "Insert Document".
Add data in JSON format. For example:
{
"order_id": "123",
"user": "chirag",
"items": [
{ "item_name": "Laptop", "quantity": 1 },
{ "item_name": "Keyboard", "quantity": 1 }
],
"total": 35000.00
}
Click "Insert".
6. Taking a Backup with mongodump (CMD)
mongodump creates a binary backup of your MongoDB data. Follow these steps:
Open Command Prompt:
Press Win + R, type cmd, and press Enter.
Run mongodump:
To back up the entire MongoDB database, run:
mongodump --uri="mongodb://localhost:27017" --out="C:\path\to\backup"
Replace "mongodb://localhost:27017" with your MongoDB connection URI, and "C:\path\to\backup" with the desired output directory for the backup files.
To back up a specific database:
mongodump --uri="mongodb://localhost:27017" --db=mydatabase --out="C:\path\to\backup"
Replace mydatabase with the name of the database you want to back up.
To back up a specific collection:
mongodump --uri="mongodb://localhost:27017" --db=mydatabase --collection=users --out="C:\path\to\backup"
Replace users with the name of the collection to back up.
Verify Backup:
Go to the specified output folder (C:\path\to\backup), where you’ll find a folder with your database dump files.
7. Restoring a Backup with mongorestore (CMD)
mongorestore restores data from binary backup files created by mongodump.
Open Command Prompt:
Press Win + R, type cmd, and press Enter.
Run mongorestore:
To restore the entire backup:
mongorestore --uri="mongodb://localhost:27017" --dir="C:\path\to\backup"
To restore a specific database:
mongorestore --uri="mongodb://localhost:27017" --db=mydatabase "C:\path\to\backup\mydatabase"
Replace mydatabase with the name of the database you want to restore.
To restore a specific collection:
mongorestore --uri="mongodb://localhost:27017" --db=mydatabase --collection=users "C:\path\to\backup\mydatabase\users.bson"
Verify Restore:
You can verify the restoration by connecting to MongoDB and checking the data.
8. Taking a Backup with MongoDB Compass
Open MongoDB Compass.
Navigate to the Database:
Connect to your MongoDB instance.
In the sidebar, select the database you want to back up.
Export Data:
Click on the Collection you want to back up.
Select Export Collection from the toolbar.
Choose either JSON or CSV format for the backup, depending on your preference.
Save the Exported Data:
Choose a location to save the file and export the data.
9. Restoring a Backup with MongoDB Compass
Open MongoDB Compass.
Navigate to the Database:
Connect to your MongoDB instance.
Import Data:
Select the database and collection where you want to restore the data.
Click Import Data from the toolbar and select the JSON or CSV file you exported.
Verify the Imported Data:
Check the collection to confirm the data was imported successfully.
For any doubts and query, please write on YouTube video comments section.
Note : Flow the Process shown in video.
Please, Subscribe and like for more videos:
https://youtube.com/@chiragstutorial
Don't forget to, Follow, Like, Share &, Comment
Thanks & Regards,
Chitt Ranjan Mahto "Chirag"
_________________________________________________________________________________________
Note: All scripts used in this demo will be available in our website.
Link will be available in description.
#mongodb
#mongodbtutorial
#mongo
#mongosh
#mongodbtutorialforbeginners
#chiragstutorial
#chiragsdatabasetutorial
#chirags
#chiragsmahto
Install MongoDB 8,Authentication,MongoDB Tutorial,MongoDB Chirags Tutorial,MongoDB DBA Tutorial,Chirags Tutorial,Chirags DBA Tutorial,Chirag Mahto,Chitt Ranjan Mahto,Chirag DBA Tutorial,Database Tutorial,NoSQL Database Tutorial,MongoDB NoSQL Database,MongoDB Install,MongoDB Configuration,MongoDB Access,MongoDB Compas,Mongosh,Rockmongo,Mongo,MongoDB Authorization,MongoDB Authentication,MongoDB Authorisation