'I'm looking to get completed events counts but this query not working
My query
let findEvents = await eventModel.aggregate([
{
$match: {
participants: {
$eq: event.userId
},
eventStatus: {
$eq: "COMPLETED"
},
},
},
{
$group: {
_id: null,
totalEvents: {
$sum: 1
},
completedEvents: {
$sum: {
$cond: {
if: {
$eq: [
"$attendants",
event.userId
]
},
then: 1,
else: 0
}
}
}
}
}
])
In this query the if condition is not working, not able to fetch userId from attendents array where userId exists. Could you explain why ?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
