当我删除用户时,我要设置一个新的Web服务,我想从Items集合(一对多关系)中删除具有提供的userId(不是_id)的注释列表,该怎么做?
这是用于节点v10.16.0猫鼬^ 5.0.9
try {
async.waterfall([ function (cb){
User
.findByIdAndDelete({ '_id': req.body.userId})
.exec((err, user) => {
if (err) {
console.log("delete user failed")
cb (err);
} else {
console.log("delete user successfully")
cb(null);
}
});
} ,
function (cb) {
Item.update(
{} ,
{multi: true},
{"$pullAll": { "userId" : req.body.userId }} )
.populate("comments")
.exec( (err, items) => {
if (err){
console.log("update many comments in item failed")
} else {
console.log("update many comments in item
successfully" );
cb(null)
}
});
},
// some other functions
] , function (err){
// error response
}
} catch (err){
// error response
}
});
这说明我操作成功,但是从未从数据库中删除