Reputation: 257
I have a collection that looks like:
{
"key": 1,
"assignments": [
{
"title" : "assignmend no 1",
"students" : [1, 13, 4, 15]
},{
"title" : "assignmend no 2",
"students" : [3, 66, 2, 13]
},{
"title" : "assignmend no 3",
"students" : [12, 13]
},{
"title" : "assignmend no 3",
"students" : [2]
}
]
}
The collection represent a class with multiple students and multiple assignments. Each student can be assigned to multiple assignments and each assignment can have multiple students.
I want to create a query that given an _id of the class and a student_id removes the student from each task it is assigned to.
How can I achive that?
Upvotes: 0
Views: 56
Reputation: 134
Class.findOneAndUpdate({ _id: 'classID' }, { $pull: { 'assignments.students': 'studentID' }});
Let me know if this works
Upvotes: 1