I'm trying to remove a lesson based on lesson_id from the following.
{
"_id" : ObjectId("5807f3f"),
"title" : "Title",
"lessons" : [
{
"lesson_id" : ObjectId("58073"),
"_id" : ObjectId("58074")
},
{
"lesson_id" : ObjectId("5807f5"),
"_id" : ObjectId("5807f6")
},
{
"lesson_id" : ObjectId("58077"),
"_id" : ObjectId("5807f4")
}
],
"__v" : 0
}
I've tried $pull and $unset, but with both my code seems to just set lessons.lesson_id to null and keep the lessons._id
Is there anyway to remove both from the object?
module.exports.deleteLessonFromClass = function(id, lesson_id, callback){ Class.update(
{'_id': id},
{ $unset: {lessons: {lesson_id: lesson_id}}},
callback
) }