【发布时间】:2016-04-07 11:53:43
【问题描述】:
文章对象数组示例:
[
{
"_id": "72",
"title": "Some title",
"comments": [
{
"title": "title 1",
"_id": "0",
},
{
"title": "title 2",
"_id": "1",
},
{
"title": "title 3",
"_id": "2",
}
]
},
(...)
]
我想根据他们的 cmets 标题(已填充)查找一些文章
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()
【问题讨论】:
-
谢谢@JohnnyHK 我尝试了另一种方式,如果你可以看看我的更新:p
标签: javascript node.js mongodb mongoose