Write Query: Grouping Across Collections
The task involves aggregating data from two collections: products and orders, to generate a report for 2025. The report should list each product's name, total quantity sold, and total revenue generated, while excluding customers with no purchases. The expected output format includes the product ID, total quantity sold, and total revenue, represented as numerical values. This requires using MongoDB's aggregation framework to effectively group and calculate the necessary metrics from the provided sample documents.
We'll cover the following...
We'll cover the following...
Question
Given the following sample documents from the products collection:
[
{
"_id": "a101a9c0c1f9472db1c01a11",
"name": "Laptop",
"category": "Computers",
"brand": "Zenbyte",
"price": 899,
"stock": 34,
"status": "Active",
"tags": ["portable", "work", "student"],
"rating": 4.7
},
{
"_id": ...