My question is, given few documents like this one
{
deliveryDay: "2021-01-14",
plate: {
name: "pasta",
quantity: 1
}
}
{
deliveryDay: "2021-01-16",
plate: {
name: "pasta",
quantity: 3
}
}
{
deliveryDay: "2021-01-16",
plate: {
name: "pizza",
quantity: 2
}
}
There's a way to obtain the wanted result below? I tried to have a custom named field with $addFields
like this {"$deliveryDay": "$plate.quantity" }
but gives me invalid error. The aggregation is not a problem to do and I'm inside the aggregation-framework so I need to do it using aggregation pipeline stages.
Attended result:
{
"2021-01-14": 1,
"2021-01-16": 3,
plate: {
name: "pasta"
}
}
{
"2021-01-14": 0,
"2021-01-16": 2,
plate: {
name: "pizza"
}
}