在Mongodb中搜索并返回嵌套值

时间:2012-10-29 15:04:45

标签: mongodb find

我有Question.findOne()返回的以下数据结构:

Object
_id: "8132c2f0-baee-434f-a739-c4d30718daf2"
owner: "273b7291-df2b-494c-bd9b-64e71283447e"
question: "Vacations?"
answers: Array[1]
  0: Object
  name: "Cancun"
  owned_by: "273b7291-df2b-494c-bd9b-64e71283447e"
  __proto__: Object

我如何findreturn使用mongodb _id "8132c2f0-baee-434f-a739-c4d30718daf2"使用此文档获得一系列答案?这是我开始的地方:

Questions.find({}, {"answers.name":1})

1 个答案:

答案 0 :(得分:0)

db.Questions.findOne({_id:"8132c2f0-baee-434f-a739-c4d30718daf2"}, {answers:1});

请同时查看文档:

http://www.mongodb.org/display/DOCS/Retrieving+a+Subset+of+Fields