我有以下文件
{
"_id" : "someId",
"name" : "myTeam",
"team" : [
{
"entity" : "size",
"value" : 14
},
{
"entity" : "returns",
"value" : 45
}
]
}
我需要检索所有大小值> 10的团队。如何在 mongoDB 中实现这一目标?
最佳答案
你可以这样做:
db.collection.find( { team:
{ $elemMatch:
{ value:
{ $gt: 10 },
entity: 'size'
}
}
}
)
关于javascript - 子数组上的 MongoDB 查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24245761/