I have some complex object model looks like this :
courses: [
{
"name": "Linux",
"slug": "linux",
"_id": "123213123123",
"sections": [
{
"name" : "section1",
"_id": "123123123",
"lessons": [
{
"title": "lesson1"
"content": "some content"
}
]
},
{
"name" : "section2",
"_id": "1231231444",
"lessons": [
{
"title": "lesson1"
"content": "some content"
}
]
}
]
}
]
I'm trying to push to specific section lessons with $push without success,
My code:
const updatedCourse = await Course.findOneAndUpdate(
{ slug: courseSlug },
{
$push: {
'sections.lessons': { title, content, free_preview, video: videoKey },
},
},
{ new: true, useFindAndModify: false }
);
Need help with mongoose expression to find section by id and push to lessons array, thanks .