Hello everyone,
I’ve recently begun my journey into databases and decided to dive into MongoDB, one of the most widely used NoSQL databases. Unlike relational databases that rely on structured tables, MongoDB works with flexible, JSON-style documents. This makes it much easier to handle unstructured or evolving data and is especially useful for applications that demand high scalability and adaptability.
1.Getting Started
My MongoDB journey began with the installation process. Once it was set up, I created a database named Business and a collection called Review to begin experimenting with data storage.
2.Importing the Dataset
After setting up the database, I brought in my dataset “yelp.json”, which contains around 1000 records, to start working with real-world data.
3.Inserting Multiple Documents with insertMany()
Once the dataset was imported, I practiced adding data by inserting 10 documents into the collection using the insertMany() method.
After inserting the datasets
4.Query to Find Top 5 Businesses with Highest Average Rating
Next, I used the aggregate function to calculate and retrieve the Top 5 businesses based on their average ratings.
db.reviews.aggregate([
{ $group: { _id: "$business_id", avg_rating: { $avg: "$stars" } } },
{ $sort: { avg_rating: -1 } },
{ $limit: 5 }
])
5.Query to Count Reviews Containing the Word “good”
I applied the countDocuments method to determine the total number of reviews that include the word “good”.
db.reviews.countDocuments({ text: /good/i })
6.Query to Retrieve Reviews for a Specific Business ID
I used the find() method to fetch all the reviews linked to a particular business ID.
db.reviews.find({ business_id: "B101" })
7.Update a review and delete a record
7.1: Updating a Review
I updated a single document in the collection by using the updateOne() method.
db.reviews.updateOne(
{ review_id: "R107" },
{
$set: {
stars: 4,
text: "The food was good and the service was friendly. I enjoyed the atmosphere, but I felt it was a bit crowded."
}
}
);
7.2: Deleting a Record
I removed one document from the collection by applying the deleteOne() method.
db.reviews.deleteOne(
{ review_id: "R104" }
);
Conclusion
Through this task, I gained practical exposure to how MongoDB can manage and analyze diverse datasets effectively. I explored different operations such as inserting documents, retrieving records, running queries with conditions, performing aggregations, and applying update/delete operations. These activities helped me understand how NoSQL databases handle information dynamically compared to traditional relational databases.
This mini-project gave me the confidence to work with unstructured data and highlighted the importance of MongoDB in modern data-driven applications. Moving forward, I am eager to dive deeper into advanced concepts like replication, sharding, and performance optimization, which are crucial for building scalable real-world systems.
Top comments (0)