当我通过962122961v时,findOneAndRemove删除错误的用户,它将删除962122963v

时间:2019-01-04 02:23:54

标签: node.js mongodb mongoose

router.delete('/user/:userId', (req ,res) => {
    User.findOneAndRemove(req.params.userId, (err, doc) => {
        if(!err) { res.send(doc); }
        else {console.log('Error in Insurance agent Delete :' + JSON.stringify(err, undefined, 2)); }
    });
});

enter image description here

1 个答案:

答案 0 :(得分:0)

findOneAndRemove()方法需要一个对象作为查询参数。所以代替:

User.findOneAndRemove(req.params.userId, (err, doc) => {

使用此:

User.findOneAndRemove({userId: req.params.userId}, (err, doc) => {