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