猫鼬选择限制1数据子文档

时间:2017-05-06 14:51:34

标签: node.js mongodb mongoose

我有这种数据。

import io

......

# get imagepath
image_path = get_image_path(image_lists, INPUT_DATA, index, category)
# read image
data = open(image_path,'rb').read()
ifile = io.BytesIO(data)
im = Image.open(ifile).convert('RGB')
ofile = io.BytesIO()
im.save(ofile, 'JPEG')
image_data = ofile.getvalue()

# calculate the feature vector
bottleneck_values = sess.run(bottleneck_tensor, {jpeg_data_tensor: image_data})

我想通过子文档列表'123'中的_id选择只有1个数据。

我做了它
{
    title : "Title",
    List : [
        {
            _id : '123',
            content : "Hello"
        },
        {
            _id : '234',
            content : "World"
        }
    ]
}

但是,结果不像我期望的那样。他们只返回这样的List数据吗?

MyModel.find({'List._id' : 123}, {"List.$": 1}, function(err, doc){
    if (err){
        res.send(err);
    }
    else{
        // data here
    }
})

如何选择包含父文档,结果就像这样。

{[
    List : [
        {
            _id : '123',
            content : "Hello"
        }
    ]
]}

0 个答案:

没有答案
相关问题