mongoDB に「CanvasCollection」という名前の次のコレクションがあり、このコレクション内の配列から「50e6fcc2edcbc10613000022」の ID を持つ画像オブジェクトを取得したいと考えています。
{
"_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",)
}