Reputation:
i need to know why my put request does not work, i am using postman to watch the result and i get a "cannot put to movieID", the movie id exist
my put code is like this
router.put('/movies:id',function(req,res){
Movie.findOneAndUpdate(req.params.id,{title:"the gift4",releaseYear:"2012",director:"stefan",genre:"horror"},function(err){
if(err){
return res.send(err);
}
console.log({message:"movie updated"});
});
});
i had a solution where i past the req.body as the second parameter and then on postman i defined the req.body dunno if that was the problem on that case, but this solution does not work either, what am i doing wrong?
Upvotes: 0
Views: 2573
Reputation:
Well i discovered my own issue, the thing is that i was routing to /movies:id i could not get the req.params.id, because i missed a slash, it should be /movies/:id so the right answer is here:
router.put('/movies/:id',function(req,res){
Movie.findOneAndUpdate(req.params.id,{title:"the gift4",releaseYear:"2012",director:"stefan",genre:"horror"},function(err){
if(err){
return res.send(err);
}
console.log({message:"movie updated"});
});
});
Upvotes: 2