I want to achieve $sum with $cond by having $or on property:
db.collectionName.aggregate(
{
\"$group\": {
\"_id\":\'$created_at\',
\"count\": {\"$su
First you should create a list of $id
using $map in project and then use setIsSubset in group as below :
db.collectionName.aggregate([{
"$project": {
"idsArray": {
"$map": {
"input": ["A"],
"as": "el",
"in": {
"$cond": [{
"$eq": ["$$el", "A"]
}, "$id",
null
]
}
}
}
}
}, {
"$group": {
"_id": "$created_at",
"count": {
"$sum": 1
},
"count_failure": {
"$sum": {
"$cond": [{
"$setIsSubset": ["$idsArray", [
0,
100,
101,
102,
103,
104,
105
]]
},
1,
0
]
}
}
}
}])