Node.js MongoDB – 如何使用Mongoose更新多个文档?

我有一个users集合,每个user都有一些联系人。 当user删除他们的帐户时,我希望这个用户的ID将被删除从这个用户连接的所有用户的联系人数组中。 我已经试过这个Model.Update查询,但它不起作用。 这是我的代码到目前为止:

  User.update({'userId':{ $in: userIds }, $pullAll: {'contacts': [myId] },'multi': true },function(err, count) { if(err){ console.log(err); }else{ console.log(count); } }); 

更新文档和multi应该作为单独的parameter passing:

 User.update({ userId : { $in : userIds } // conditions }, { $pullAll : { contacts : [myId] } // document }, { multi : true // options }, function(err, count) { if (err) { console.log(err); } else { console.log(count); } }); 

文档在这里 。