DB item:
{
name: "bicycle"
category: [ "transport", "sport" ],
status: "present" or "deleted"
}
I need result - categoryName: items quantity
const data = await Product.aggregate([
{$unwind: "$category"},
{$group: {_id: "$category", quantity: {$sum: 1}}}
])
But I tried to get only “present” items.
const data = await Product.aggregate([
{$unwind: "$category"},
{$group: {_id: "$category", quantity: {
$sum: { $cond: { if: { "status": "present" }, then: 1, else: 0}}
}}}
])
result is the same !
Why my condition doesn’t work ?