无法使用nodeJS从mongodb中删除特定记录(文档)

时间:2018-12-19 10:25:18

标签: javascript node.js handlebars.js

router.get('/deleteRecord/delete/:id', function(req, res){
  db.collection('inventories').remove({_id: mongodb.ObjectID( req.params.id)}, (err, result) => {
    if (err) return console.log(err)
    console.log('Welcome to Delete Function');
    res.redirect('deleteRecord');
  });
});

车把:Delete

获取ID,但记录并未被删除

1 个答案:

答案 0 :(得分:0)

尝试

 db.collection('inventories').find({_id: mongodb.ObjectID( req.params.id)}).remove()