對于包含欄位的檔案:
{"_id" : 1, "name": "Sarah", "fruitEaten : ["apple", "banana", "orange"]}
{"_id" : 2, "name": "Steve", "fruit Eaten : "apple"}
{"_id" : 3, "name": "Stacey", "fruitEaten : ["apple", "orange"]}
如何查詢誰吃了不止一種水果?
我已經試了db.collection.find({"fruitEaten":{"$gt":1},{"name":1}})
uj5u.com熱心網友回復:
db.collection.aggregate([
{
$match: {
$expr: {
$and: [
{
$isArray: "$fruitEaten"
},
{
$gt: [ { $size: "$fruitEaten" }, 1 ]
}
]
}
}
}
])
mongoplayground
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/438168.html
標籤:数组 json mongodb mongodb查询 nosql
下一篇:使用沒有所有鍵的內部陣列解構物件
