app.post ('/create_contact',function(req,res)
{
contact.create({
name :req.body.name,
phone:req.body.phone
},function(err,newContact)
{
if(err){console.log('error in creating a contact!');
return;}
console.log('********',newContact);
return res.redirect('back');
});
});
Errors:
throw new MongooseError('Model.create() no longer accepts a callback');
^
MongooseError: Model.create() no longer accepts a callback
I tried this code but again showing error
2
Answers
Mongoose has dropped support for callbacks to some of it’s methods (The create method is one of them). You can check out this link to see more about it. And instead of using callbacks, using async/await syntax and wrap it with a try/catch block to handle errors that might happen on creation of a new document.
Check this this duplicate question. Your question will be flagged.
You can solve it with
async await