I want to remove a particular chapter from a course from my MongoDB. For example i want to remove "chapterid": 5 from "courseid" 1. This is what i am trying right now:
db.users.update({
$and:
[
{
"email": roshan_raj@gmail.com
},
{
"courses.courseid": 1
}
]
},
{
$pull: {
"courses": {
"chapterid": 5
}
}
});
But this query is deleting both the object where there is a chapterid: 5
This is how my DB looks like.
{
"_id" : ObjectId("5e94393709d9194874cdb1d3"),
"email" : "roshan_raj@gmail.com",
"courses" : [
{
"courseid" : "1",
"chapterid" : 5
},
{
"courseid" : "2",
"chapterid" : 5
},
{
"courseid" : "2",
"chapterid" : 6
},
],
"__v" : 0
}
Any help is appreciated. Thank You.