Quantcast
Channel: Active questions tagged javascript - Stack Overflow
Viewing all articles
Browse latest Browse all 138249

post request using deleteOne method to delete an item from a mongodb database

$
0
0

I'm taking a Nodejs course and I am following along.

I did write the same code as the instructor did and when I execute the code it gives me this error

Cannot read property 'id' of undefined

The error occurred when I tried to delete an item from a MongoDB database using the deleteOne method here is the code:

app.post('/delete-item',function(res,req){
  db.collection('item').deleteOne({_id:new mongodb.ObjectId(req.body.id)},function(){
    res.send("success")
  })
})

Viewing all articles
Browse latest Browse all 138249

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>