``# ๐งฉ MongoDB Atlas: Insert, Query, Update, Delete, and Export Data
Author: NAVEEN GOKUL S
Date: November 2025
Topic: Data Engineering Assignment โ MongoDB CRUD Operations
๐๏ธ Step 1: Setting up MongoDB Atlas
- Go to MongoDB Atlas.
- Create a free cluster (use the Shared Tier option).
- Under Network Access, add your IP:
- Click Network Access โ Add IP Address โ Allow access from anywhere (0.0.0.0/0).
- Create a database user and remember the credentials. Example:
`
Username: 22cs098
Password: NAVEEN
`
- Once your cluster is ready, click โConnect โ Connect using MongoDB Shellโ and copy the connection string.
๐ป Step 2: Connect from Mongo Shell
Open PowerShell or Command Prompt, then run:
`bash
mongosh "mongodb+srv://m0.wpjmxqh.mongodb.net/" --apiVersion 1 --username 22cs098_db_user
`
Then enter your password when prompted:
`
Enter password: NAVEEN
`
If connection succeeds, youโll see:
`
Atlas atlas-xxxx-shard-0 [primary]>
`
๐ฅ Step 3: Create a Database and Insert Records
Switch to a database (it will auto-create):
`javascript
use businessDB
`
Insert 10 sample business review records:
`javascript
db.reviews.insertMany([
{ "business_id": "B001", "name": "Cafe Aroma", "rating": 4.6, "review": "Good food and fast service!", "date": "2025-11-07" },
{ "business_id": "B002", "name": "Pizza Palace", "rating": 4.8, "review": "Amazing crust and cheese quality!", "date": "2025-11-07" },
{ "business_id": "B003", "name": "Tea Time", "rating": 4.2, "review": "Nice ambience and friendly staff.", "date": "2025-11-07" },
{ "business_id": "B004", "name": "Sweet Treats", "rating": 3.9, "review": "Desserts were good but service was slow.", "date": "2025-11-07" },
{ "business_id": "B005", "name": "Veggie Delight", "rating": 4.1, "review": "Healthy food with good taste.", "date": "2025-11-07" },
{ "business_id": "B006", "name": "Burger Hub", "rating": 4.9, "review": "Best burgers ever!", "date": "2025-11-07" },
{ "business_id": "B007", "name": "Ocean Dine", "rating": 4.7, "review": "Fresh seafood and great view.", "date": "2025-11-07" },
{ "business_id": "B008", "name": "Spice Route", "rating": 3.8, "review": "Food was okay, but spicy.", "date": "2025-11-07" },
{ "business_id": "B009", "name": "Bakers Street", "rating": 4.5, "review": "Good pastries and coffee.", "date": "2025-11-07" },
{ "business_id": "B010", "name": "Quick Bite", "rating": 4.0, "review": "Good service and clean place.", "date": "2025-11-07" }
])
`
๐ Step 4: Queries
๐ 4.1 Top 5 Businesses by Rating
`javascript
db.reviews.find().sort({ rating: -1 }).limit(5)
`
๐ค 4.2 Count of Reviews Containing โgoodโ
`javascript
db.reviews.countDocuments({ review: /good/i })
`
๐ช 4.3 Get Reviews for a Specific Business ID
`javascript
db.reviews.find({ business_id: "B005" })
`
โ๏ธ Step 5: Update and Delete
โ๏ธ Update a Review
`javascript
db.reviews.updateOne(
{ business_id: "B005" },
{ $set: { rating: 4.3, review: "Updated: Great taste and fresh ingredients!" } }
)
`
๐๏ธ Delete a Record
`javascript
db.reviews.deleteOne({ business_id: "B010" })
`
๐ค Step 6: Export Data to JSON/CSV
Exit Mongo shell:
`bash
exit
`
Then run the following from PowerShell (not inside mongosh) ๐
๐ Export as CSV
`bash
mongoexport --uri="mongodb+srv://22cs098_db_user:NAVEEN@m0.wpjmxqh.mongodb.net/businessDB" --collection=reviews --type=csv --fields=business_id,name,rating,review,date --out=reviews.csv
`
๐ฆ Export as JSON
`bash
mongoexport --uri="mongodb+srv://22cs098_db_user:NAVEEN@m0.wpjmxqh.mongodb.net/businessDB" --collection=reviews --out=reviews.json
`
๐ Step 7: View the Exported Files
- Open reviews.csv in Excel or VS Code.
- Open reviews.json in any text editor.
โ Step 8: Summary
| Operation | Command Type | Example |
|---|---|---|
| Insert | insertMany() |
Add 10 reviews |
| Query |
find(), countDocuments()
|
Search data |
| Update | updateOne() |
Modify rating/review |
| Delete | deleteOne() |
Remove record |
| Export | mongoexport |
CSV/JSON output |
๐ฏ Final Thoughts
MongoDB Atlas makes it easy to:
- Manage cloud-hosted databases
- Perform CRUD operations
- Export results in multiple formats
This project demonstrates all essential MongoDB operations โ perfect for Data Engineering and Database Management learning tasks.






Top comments (0)