This repository contains comprehensive notes and code examples for MongoDB aggregation pipeline operations. The code files provide examples of how to utilize various stages and operators to handle complex data queries and transformations in MongoDB.
File | Description |
---|---|
Q1.json | Filters active users and counts them. |
Q2.json | Groups by gender and calculates the average age. |
Q3.json | Groups by favorite fruit, counts occurrences, sorts by count, and limits results to top two. |
Q4.json | Groups by gender and counts the number of users per gender. |
Q5.json | Groups by country and counts users, sorts by user count, and limits to the top two countries. |
Q6.json | Filters active users. |
Q7.json | Unwinds tags , counts tags per user, calculates the average number of tags. |
Q8.json | Filters users with the tag “enim” and counts them. |
Q9.json | Filters inactive users with the tag “velit”, projects their name and age. |
Q10.json | Filters users whose phone number matches a specific pattern and counts them. |
Q11.json | Sorts by registration date, limits to 10 users, and projects name, registration date, and favorite fruit. |
Q12.json | Groups users by favorite fruit and collects their names. |
Q13.json | Filters users where the second tag is “ad” and counts them. |
Q14.json | Matches users who have both “enim” and “id” tags. |
Q15.json | Groups users by company title and counts the number of users in the USA. |
Q16.json | Uses $lookup to join authors collection and adds the author’s details to each document. |