DEV Community

jayanth anbu
jayanth anbu

Posted on

Exploring NoSQL Data Analysis: A Practical Study Using a Kaggle Dataset

πŸ—‚οΈ 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)