{
"_id" : ObjectId("5234ccb7687ea597eabee677"),
"code" : "efg",
"tags" : [ "school", "book"],
"qty" : [
{ "_id":"1", "size" : "S", "num" : 10, "color" : "blue" },
{ "_id":"2", "size" : "M", "num" : 100, "color" : "blue" },
{ "_id":"3", "size" : "L", "num" : 100, "color" : "green" }
]
}
我有一个像这样的mongo文档,我只需要基于_id从“ qty”数组中查询单个元素。 那么查询语句将如何? 我尝试过:
collection.find({ _id: "","qty._id":" "},{}, (err, response) => {
//do something
});
但是它返回整个文档,包括标签,代码和qty中的所有元素。