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:
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
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加