数据:
[{
"shop_ID" : "ABCD",
"plan" : 2,
"planType" : 2,
"goods_id" : "9612",
"category" : "1",
"keywords" : [
{
"keyword" : "lianyiqun",
"price" : 3.12,
"score" : 9
},
{
"keyword" : "nvzhuang",
"price" : 6.57,
"score" : 6
},
{
"keyword" : "chunzhuang",
"price" : 5.55,
"score" : 8
}
]
},
{
"shop_ID" : "ABCD",
"plan" : 2,
"planType" : 2,
"goods_id" : "5078",
"category" : "1",
"keywords" : [
{
"keyword" : "lianyiqun",
"price" : 9.26,
"score" : 8
},
{
"keyword" : "nvzhuang",
"price" : 4.52,
"score" : 9
}
]
}]
我使用了命令查询:
db.test.find({"keywords" : { $elemMatch: {"score":{"$gte":8}} } })
结果不对,都是文件。
并且,使用命令 db.test.find({"keywords."score":{"$gte":8}})
结果是一样的。
我想要第一个文档的查询结果如下:
{
"shop_ID" : "ABCD",
"plan" : 2,
"planType" : 2,
"goods_id" : "9612",
"category" : "1",
"keywords" : [
{
"keyword" : "lianyiqun",
"price" : 3.12,
"score" : 9
},
{
"keyword" : "chunzhuang",
"price" : 5.55,
"score" : 8
}
]
},
如何查询内部文档?