I have a users collection and every user has a number of contacts. When a user deletes their account I want that this user's id would be deleted from the contacts array of all the users with who this user is connected. I have tried this Model.Update query but it doesn't work. Here is my code so far:
User.update({'userId':{ $in: userIds },
$pullAll: {'contacts': [myId] },'multi': true
},function(err, count) {
if(err){
console.log(err);
}else{
console.log(count);
}
});
userIdsis an array of id's for users that need to be removed and subsequently remove them from thecontactsarray of the other users, correct? Can you also update your question to show theUsermodel's schema definition?