I need to populate "contents" on lesson property, but the array return empty.
I'm using the plugin autopopulate and its work fine, but doesnt work with multiple levels. I tried the documentation, but 2 levels I didnt found a solutions.
It's my Schema.
const structure = {
name: {
type: String,
required: true
},
lessons: [{
name: String,
contents: [{
type: ObjectId,
ref: 'Content',
autopopulate: true
}]
}]
}
It's my query to get content.
Course.findById(contentData.course_id)
.populate({
path: 'lessons.contents',
model: 'Content'
})
.exec((err, a) => {
console.log(a);
res.status(201).json(a)
});
The array of contents in lessons return empty, but exit two registers on db.
"lessons": [
{
"contents": [],
"name": "Nova Aula"
}
],