Example of Article object array:
[
{
"_id": "72",
"title": "Some title",
"comments": [
{
"title": "title 1",
"_id": "0",
},
{
"title": "title 2",
"_id": "1",
},
{
"title": "title 3",
"_id": "2",
}
]
},
(...)
]
I would like to find some articles by their comments title (populated)
var ArticleSchema = new Schema({
title: { type: String },
comments: [{ type: Schema.ObjectId, ref: 'Comment' }]
});
I tried a lot of things like:
var options = {
criteria: {
'comments.title': regex
}
};
Article
.find(options.criteria, function (err, articles) {
if (err) throw err;
res.json(articles);
})
.populate('comments');
but does not work...
Thanks
- Update *
Here my new code: three nested find() and two forEach()