node.js - Mongoose: Update and $pull from an array of references -


my user model includes:

{_id: "genericmongoid",  friends: [{type: schema.objectid, ref:'user'}] } 

i creating function such after delete user, references user in users friends arrays removed well.

user.findbyid(req.params.id, function (err, user) {    user.remove(function(err) {        user.update(({friends: req.params.id}),{$pull: {friends:req.params.id}},    function(err, data){       console.log(err, data)... 

when run function , pass in id, reason seems delete 1 friend reference. assume i'm missing something, googling isn't finding it.

duh, add multi option

user.update({friends: req.params.id}, {$pull: {friends:req.params.id}},{multi:true}... 

Comments

Popular posts from this blog

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

linux - disk space limitation when creating war file -