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
2
Answers
you could create an aggregation pipeline in a way first group by
id
and get an array ofconditions
. then check if the condition array has true and false and create condition existing fieldscond_true
,cond_false
.If both the
cond_true
andcond_false
aretrue
it is a match.playground
One option is to use
$setIsSubset
for the generic case ofn
out ofm
wanted conditions:See how it works on the playground example