I want to update a collection called SMUProfiles
, through a method called classroom.delete
. I want to pull out the classroom_id
from 2 places inside SMUProfiles
i.e. one inside classrooms.owner
which has an array of codes, and the other inside array classrooms.students
.
I have successfully one the $set part, and now trying to add the $pull, but $pull
doesn't seem to work.
Can we do the $set
and $pull
in such way?
/* Method for deleting Classroom */
'classroom.delete'(classroom_id) {
if (!this.userId) {
throw new Meteor.Error('not-authorised');
}
Classrooms.remove(classroom_id)
let classids = Classrooms.find({ owner: this.userId }).fetch().map(function(classrooms){
return classrooms._id })
//console.log(classids);
SMUProfiles.update({
owner: this.userId,
}, {
$set: {
'classrooms.owner': classids
},
$pull: {
'classrooms.students': classroom_id
}
}
)
}