0
I’m with a study project using Node JS with Mongodb and I’m having difficulty saving a record in the database, I’m using the method this way.
function postRestaurant (req, res) {
var restaurants = new Restaurants(req.body);
restaurants
.save
((err, restStored) => {
if(err){
res.status(500).send({message: 'Error do servidor'});
}else{
if(!restStored){
res.status(404).send({message: 'No existe restaurant'});
}else{
res.status(200).send({restaurants: restStored});
}
}
});
}
When I submit the method it’s falling into error 500, where am I wrong?
Give a
console.log(err)
, to see the reason for the error.– Thiago Magalhães
Isn’t it missing to pass the object that will be saved? I’m only seeing the callback function, without the record itself.
– Lucas Brogni