我有这样的收藏:
{
"name":"silver",
mywants:[
{"_id":objid(545454ddfdf5),mark:{"english":100,"math":100,"science":100}},
{"_id":objid(5878784dfd5d),mark:{"english":100,"math":100,"science":100}},
{"_id":objid(5454dfd44545),mark:{"english":100,"math":100,"science":100}},
{"_id":objid(541dfee88245),mark:{"english":100,"math":100,"science":100}},
]
}
我想找到给定的 objid 是否存在于 mywants 数组中。然后,如果存在那个 objid 我想要那个存在的对象 id 文档到我的回调函数,所以我尝试过这样
collection.find("{"name":"silver"},{"mywants._id":objid}).toArray(function(err,res)
{
console.log(JSON.stringify(res));
})
But, I got output like
[{"Mywant":[{"_id":"5128b9bc046802720b000003"},
{"_id":"5128c190046802720b000004"},
{"_id":"5128c359175e1aa80b000001"}],"_id":"5128b71455e4e0540b000002"}
]
但我想要这样
{"_id":objid(545454ddfdf5),mark:{"english":100,"math":100,"science":100}}`,
怎么找?