ποΈ 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: 22cs056
Password: JAYANTH
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: JAYANTH
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 | Example |
|---|---|---|
| Insert | insertMany() | Add 10 review records |
| Query | find(), countDocuments() | Retrieve data |
| Update | updateOne() | Modify fields |
| Delete | deleteOne() | Remove a record |
| Export | mongoexport | Generate CSV/JSON files |
π― 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)