skip to Main Content

Mongodb – how to mongoose delete cascade in latest version of mongoose without model.remove()?

Not able to delete cascade as Model.remove() fuction is not available in mongoose. using findByIdAndDelete is not invoking the middleware: BootcampSchema.pre('remove',async function(next){ //before deleting the doc console.log(`courses being removed from bootcamp ${this._id}`); await this.model('Course').deleteMany({bootcamp:this._id}); next(); }); tried different delete methods…

VIEW QUESTION

Mongodb – MongooseError: Model.create() no longer accepts a callback how to use async await?

app.post('/contactForm',function(req,res){ Contact.create({ name: req.body.name, phone: req.body.phone }, function(err, newContact){ if(err){ console.log(err, 'error in connectiong'); return; } console.log("*******", newContact); return res.redirect('back'); }) }) /home/ganesh/Web Dev/CN Web Dev/HTML/basics/Nodejs Workspace/contact_list/node_modules/mongoose/lib/model.js:2771 throw new MongooseError('Model.create() no longer accepts a callback');

VIEW QUESTION
Back To Top
Search