我在 mongoDB 中有以下名为“CanvasCollection”的集合,我想从该集合中的数组中获取 ID 为“50e6fcc2edcbc10613000022”的图像对象:
{
"_id": ObjectId("50d1f440471ca84e1f000007"),
"image": [{
"_id": ObjectId("50e6fcc2edcbc10613000022"),
"type": "image",
"filename": "50e6fcc2edcbc10613000022.jpg",
"origname": "2811879134_7a57d7c586_m.jpg",
"filepath": "upload/50e6fcc2edcbc10613000022.jpg",
"thumbpath": "upload/50e6fcc2edcbc10613000022_small.jpg",)
}],
"text": [{
"_id": ObjectId("50e6eda0edcbc1061300001b"),
"content": "Type your text here"
}]
}
这似乎不起作用:
CanvasCollection.find({'_id': new BSON.ObjectID('50d1f440471ca84e1f000007')}, {'image' : {$elemMatch: {'_id': new BSON.ObjectID('50e6fcc2edcbc10613000022')}}})
任何想法如何得到这个:
{
"_id": ObjectId("50e6fcc2edcbc10613000022"),
"type": "image",
"filename": "50e6fcc2edcbc10613000022.jpg",
"origname": "2811879134_7a57d7c586_m.jpg",
"filepath": "upload/50e6fcc2edcbc10613000022.jpg",
"thumbpath": "upload/50e6fcc2edcbc10613000022_small.jpg",)
}