Reputation: 83
I have objects in the document that look's like:
I want to get only the elements from the 'transactions' array that their inside field 'isMatched' == false
I tried:
db.myCollection.find(
{ "transactions.isMatched": false } ,
{ "transactions.isMatched": 1
})
But i got all the array elements:
Upvotes: 1
Views: 38
Reputation: 8894
You can achieve this with aggregation. $filter
helps to eliminate unwanted objects.
db.collection.aggregate([
{
$project: {
company: 1,
transaction: {
$filter: {
input: "$transaction",
cond: {
$eq: [
"$$this.isMatched",
false
]
}
}
}
}
}
])
Working Mongo playground
Upvotes: 1