I have an collection of orders, which look like this:
[
{
_id: ObjectID,
date: Date,
products: [
{
id: string,
quantity: number
},
{
id: string,
quantity: number
},
]
}
]
I need to aggregate them so that I can determine, using a product.id, the quantity of each id for each date (not time)
My resultant data set would look something similar to this:
[
{
date: "2021-01-1",
products: {
// product_id: quantity
PRODUCT_ID_1: 4
PRODUCT_ID_2: 9
}
}
]
Any ideas on how I can do this?