I'm pulling my hair for this...trying to delete document by id:
router.delete('/api/menu/delete/:id', function (req, res) {
var id = req.params.id;
db.get().collection('menu', function (err, col) {
col.deleteOne({_id: new mongodb.ObjectID(id)});
});
res.json({ success: id })
});
Always getting :
Cannot read property deleteOne of undefined
When trying to find records it's working as expected.
Got it. First thing i require the mongodb
mongo = require('mongodb')
And then :
router.delete('/api/menu/delete/:id', function (req, res) {
var id = req.params.id;
var collection = db.get().collection('menu');
collection.deleteOne({ _id: new mongo.ObjectId(id) }, function (err, results) {
});
res.json({ success: id })
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With