2016-10-04 43 views
0

我有以下数据结构如何使用ID MongoDB中

enter image description here

enter image description here

我需要找出文档和问题有一个查询(我的文档ID搜索嵌套文件和问题ID)后,我需要更新问题与一些参数。

任何人都可以帮助我创建查询 在此先感谢! Kiran Gopal

回答

0

您可以像搜索最高级别的模型一样搜索子文档数组。

Documents.findOne({'_id' : 'your doc ID', 'question.question_id': 'your question id'}, function (err, document) { 
    for(var i = 0; i < document.length; i++){ 
     console.log(document.question[i]); 
    } 
}); 
+0

嗨汤姆,但问题是里面的部分列表>问题列表 –

+0

对不起,没有看到二维数组。猫鼬不支持。你必须重新安排你的方案,以利用猫鼬所提供的好处。你想要做的是使用'人口':http://mongoosejs.com/docs/populate.html – Tom