{"id":21964672,"url":"https://github.com/apollo-level2-web-dev/mongoose_practice-aggregation","last_synced_at":"2025-03-22T21:25:26.055Z","repository":{"id":166647691,"uuid":"642149704","full_name":"Apollo-Level2-Web-Dev/mongoose_practice-aggregation","owner":"Apollo-Level2-Web-Dev","description":null,"archived":false,"fork":false,"pushed_at":"2023-05-18T00:08:40.000Z","size":2,"stargazers_count":2,"open_issues_count":0,"forks_count":4,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-01-28T01:17:09.803Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":null,"has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Apollo-Level2-Web-Dev.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-05-17T23:53:22.000Z","updated_at":"2024-04-02T00:04:08.000Z","dependencies_parsed_at":null,"dependency_job_id":"d8952e94-16bb-4ec1-99c1-2e47ab06d684","html_url":"https://github.com/Apollo-Level2-Web-Dev/mongoose_practice-aggregation","commit_stats":null,"previous_names":["apollo-level2-web-dev/mongoose_practice-aggregation"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Apollo-Level2-Web-Dev%2Fmongoose_practice-aggregation","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Apollo-Level2-Web-Dev%2Fmongoose_practice-aggregation/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Apollo-Level2-Web-Dev%2Fmongoose_practice-aggregation/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Apollo-Level2-Web-Dev%2Fmongoose_practice-aggregation/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Apollo-Level2-Web-Dev","download_url":"https://codeload.github.com/Apollo-Level2-Web-Dev/mongoose_practice-aggregation/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245021753,"owners_count":20548397,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-29T12:26:42.414Z","updated_at":"2025-03-22T21:25:26.025Z","avatar_url":"https://github.com/Apollo-Level2-Web-Dev.png","language":null,"readme":"# mongoose Practice Aggregation\n## Example data:\n\n```js\n[\n   {\n     \"name\": \"John Doe\",\n     \"email\": \"johndoe@example.com\",\n     \"age\": 28,\n     \"address\": {\n       \"street\": \"123 Main St\",\n       \"city\": \"New York\",\n       \"state\": \"NY\",\n       \"zipcode\": \"10001\"\n     },\n     \"favorites\": {\n       \"color\": \"blue\",\n       \"food\": \"pizza\",\n       \"movie\": \"The Shawshank Redemption\"\n     },\n     \"friends\": [\n       {\n         \"name\": \"Jane Smith\",\n         \"email\": \"janesmith@example.com\"\n       },\n       {\n         \"name\": \"Mike Johnson\",\n         \"email\": \"mikejohnson@example.com\"\n       }\n     ]\n   },\n   {\n     \"name\": \"Alice Williams\",\n     \"email\": \"alicewilliams@example.com\",\n     \"age\": 35,\n     \"address\": {\n       \"street\": \"456 Elm St\",\n       \"city\": \"San Francisco\",\n       \"state\": \"CA\",\n       \"zipcode\": \"94101\"\n     },\n     \"favorites\": {\n       \"color\": \"green\",\n       \"food\": \"sushi\",\n       \"movie\": \"The Godfather\"\n     },\n     \"friends\": [\n       {\n         \"name\": \"Bob Anderson\",\n         \"email\": \"bobanderson@example.com\"\n       },\n       {\n         \"name\": \"Emily Davis\",\n         \"email\": \"emilydavis@example.com\"\n       }\n     ]\n   }\n ]\n```\n\n**Task 1:** Find all users who are located in New York.\n\n**Task 2:** Find the user(s) with the email \"**[johndoe@example.com](mailto:johndoe@example.com)**\" and retrieve their favorite movie.\n\n**Task 3:** Find all users with \"pizza\" as their favorite food and sort them according to age.\n\n**Task 4**: Find all users over 30 whose favorite color is \"green\".\n\n**Task 5:** Count the number of users whose favorite movie is \"The Shawshank Redemption.\"\n\n**Task 6:** Update the zipcode of the user with the email \"**[johndoe@example.com](mailto:johndoe@example.com)**\" to \"10002\".\n\n**Task 7:** Delete the user with the email \"**[alicewilliams@example.com](mailto:alicewilliams@example.com)**\" from the user data.\n\n**Task 8**: Group users by their favorite movie and retrieve the average age in each movie group.\n\n**Task 9:** Calculate the average age of users with a favorite \" pizza \" food.\n\n```js\n// orders\n[\n  {\n    \"_id\": 1,\n    \"order_number\": \"ORD-001\",\n    \"customer_id\": 1,\n    \"total_amount\": 100.0\n  },\n  {\n    \"_id\": 2,\n    \"order_number\": \"ORD-002\",\n    \"customer_id\": 2,\n    \"total_amount\": 150.0\n  },\n  {\n    \"_id\": 3,\n    \"order_number\": \"ORD-003\",\n    \"customer_id\": 1,\n    \"total_amount\": 200.0\n  }\n]\n\n// customers\n[\n  {\n    \"_id\": 1,\n    \"name\": \"Alice Williams\",\n    \"email\": \"alice@example.com\"\n  },\n  {\n    \"_id\": 2,\n    \"name\": \"Bob Anderson\",\n    \"email\": \"bob@example.com\"\n  },\n  {\n    \"_id\": 3,\n    \"name\": \"Emily Davis\",\n    \"email\": \"emily@example.com\"\n  }\n]\n```\n\n**Task 10:** Perform a lookup aggregation to retrieve the orders data along with the customer details for each order.\n\n## More Tasks on Aggregation\n\n**Task 1:** Group users by their favorite color and retrieve the count of users in each color group.\n\n**Task 2:** Find the user(s) with the highest age.\n\n**Task 3:** Find the most common favorite food among all users.\n\n**Task 4:** Calculate the total count of friends across all users.\n\n**Task 5:** Find the user(s) with the longest name.\n\n**Task 6:** Calculate each state's total number of users in the address field.\n\n**Task 7:** Find the user(s) with the highest number of friends.\n\nThese tasks involve using various aggregation operators such as **`$group`**, **`$avg`**, **`$max`**, **`$sum`**, and **`$project`** to perform complex calculations and data transformations. You can write MongoDB aggregation queries to accomplish each task based on user data. Adjust the queries according to your specific implementation and requirements.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fapollo-level2-web-dev%2Fmongoose_practice-aggregation","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fapollo-level2-web-dev%2Fmongoose_practice-aggregation","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fapollo-level2-web-dev%2Fmongoose_practice-aggregation/lists"}