DEV Community

Jenisha E
Jenisha E

Posted on

NoSQL - MongoDB Hands-On

I recently started exploring NoSQL databases, and MongoDB caught my attention because it stores data in a simple, JSON-like format. Instead of using rows and columns like SQL, MongoDB feels more natural — almost like handling real-world objects.

For practice, I picked the Yelp dataset. Imagine having access to thousands of businesses, ratings, and reviews — it’s perfect for testing queries.

I uploaded the dataset into MongoDB

1.Insert at least 10 records manually
To start working with MongoDB, I first inserted 10 sample business records manually into my businesses collection. This step helps in understanding how MongoDB stores data in a JSON-like structure.

Each record represents a business with details like name, city, rating, and category.

2.Query to find top 5 businesses with highest average rating
Next, I wanted to see the top 5 businesses based on their ratings. I used MongoDB’s sort() function to arrange businesses in descending order of ratings and limited the results to 5.

This query is useful when we want to highlight the best-rated businesses.

3.Query to count how many reviews contain the word "good"
To analyze customer feedback, I searched for all reviews that contained the word “good”. I used a regular expression in MongoDB to match the word inside the review text.

The query then counts the total number of matching reviews. This kind of query helps us understand customer sentiment.

4.Query to get all reviews for a specific business ID
In real-world applications, we often need to check all reviews for a particular business. By using the business_id as a filter, I retrieved all the reviews linked to that business.

This helps in analyzing customer opinions for a single location or brand.

5.Update to get all review and delete a record

    Finally, I explored how to update and delete records in MongoDB.
Enter fullscreen mode Exit fullscreen mode

With updateOne(), I modified an existing review to test how updates work.

With deleteOne(), I removed a record from the collection.

Top comments (0)