Suppose I have the following documents:
{
"_id": "ID1",
"A": [
{
"a": "abc",
"b": true
},
{
"a": "abc",
"b": false
},
{
"a": "def",
"b": true
}
]
}
{
"_id": "ID2",
"A": [
{
"a": "abc",
"b": false
},
{
"a": "abc",
"b": false
},
{
"a": "def",
"b": true
}
]
}
How can I adjust my query:
db.collection.aggregate([
{$match: {"A.a": "abc"}},
{$project: {A: 1}}
])
So that I match only documetns where there is at least one object in A where A.a=abc AND A.b=true? In this example the outcome would be just:
{
"_id": "ID1",
"A": [
{
"a": "abc",
"b": true
},
{
"a": "abc",
"b": false
},
{
"a": "def",
"b": true
}
]
}