I want to get the number of items that meet the true condition in the status field for every cases. for example: Document
Output:
{“user_id”: “4-389-739”,“case1”:0,“case2”:3,“case3”:1,“case4”:1 }
I want to get the number of items that meet the true condition in the status field for every cases. for example: Document
Output:
{“user_id”: “4-389-739”,“case1”:0,“case2”:3,“case3”:1,“case4”:1 }
The user id part is not sure from where you are getting in document i believe you can figure it out but for help you out with counting the cases this might help you
{
$group: {
"case1": {
$sum: {
$cond: [{ $in: [true, "$case1.status"] }, 1, 0]
}
},
"case2": {
$sum: {
$cond: [{ $in: [true, "$case2.status"] }, 1, 0]
}
}
}
}
you can generalize here and add as many conditioin as possible