Tuesday, 25 April 2017

Node.js MongoDB - How to update multiple documents with Mongoose?

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);
                        } 
                    });



via Nikolaj

No comments:

Post a Comment