1
[
{
"_id": "72",
"title": "Some title",
"comments": [
{
"title": "title 1",
"_id": "0",
},
{
"title": "title 2",
"_id": "1",
},
{
"title": "title 3",
"_id": "2",
}
]
},
(...)
]
我想找到他们的评论标题(填充)
var ArticleSchema = new Schema({
title: { type: String },
comments: [{ type: Schema.ObjectId, ref: 'Comment' }]
});
我尝试了很多东西像一些文章:
var options = {
criteria: {
'comments.title': regex
}
};
Article
.find(options.criteria, function (err, articles) {
if (err) throw err;
res.json(articles);
})
.populate('comments');
但不工作...
感谢
- 更新*
这里我的新代码:三个嵌套find()方法和两个forEach()这样
可能重复的[Mongoose查询填充字段](http://stackoverflow.com/questions/17535587/mongoose-query-a-populated-field) – JohnnyHK
谢谢@JohnnyHK我试了另一种方式,如果你可以采取看看我的更新:页 – user3366589