在mongodb中找到具有特定id和用户名的子文档

时间:2014-05-16 04:19:04

标签: node.js mongodb express

 {
 _id:"101",
 title : "this is title",
 comments: 
 [{
    username : "mark zucker",
    comment: "awsome"
    }]

  }

我试图用用户名"标记zucker"来获得评论。通过以下代码

 app.get('/all',function(req , res){
 db.collection.find({"_id":101},{"comments.username":'mark zucker'},function(err,docs){res.send(docs,{data:docs});});
 } );

但我得到的输出为

  {
  "data": [
    {
     "_id": 101,
     "comments": [
      {
        "user": "mark zucker"
      },
       {
        "user": "bella"
      }
    ]
    } 
 ]
  }

请帮助我只使用用户名获得特定评论:" mark zucker"

0 个答案:

没有答案