I have these documents:
[
{
"id": 1,
"condition": true
},
{
"id": 1,
"condition": false
},
{
"id": 2,
"condition": true
},
]
In this case I want the output to be "id": 1, since it has condition as both true and false ("id": 2 only has condition as true, so it does not qualify)
Thank you
>Solution :
One option is to use $setIsSubset for the generic case of n out of m wanted conditions:
db.collection.aggregate([
{$group: {
_id: "$id",
conditions: {$addToSet: "$condition"}
}},
{$match: {$expr: {
$setIsSubset: [
[true, false],
"$conditions"
]
}
}},
{$project: {id: 1}}
])
See how it works on the playground example