在mongodb中的数组内搜索id

时间:2014-02-23 19:06:05

标签: mongodb

我有以下mongo对象:

{
  "_id" : ObjectId("530a40b72098b01011000002"),
  "content" : "hellp world",
  "comments" : [
    {
      "_id" : ObjectId("530a419f5dfb071912000003"),
      "data" : {
        ...
      }
    },
    {
      "_id" : ObjectId("530a419f5dfb071912000004"),
      "data" : {
        ...
      }
    },
  ],
}

有没有办法可以通过使用comments数组中的_id来查询它?

1 个答案:

答案 0 :(得分:0)

有了类似的东西,它应该有效:

.find({ 'comments._id': 530a419f5dfb071912000004 }).select('comments.data').run(function(err, result){ //blablabla })

相关问题