Reputation: 433
I try to update a field in my collectionObject. This is my attempt, but not working. My get api for a specific item does work.
app.put('/api/beers/:id/comment', (req,res) =>{
Beer.findByIdAndUpdate(req.params.id, function(err, beer){
beer.name='newName';
});
});
can someone explain me, why it's not working? Much appreciated, thanks!
Upvotes: 1
Views: 129
Reputation: 10148
This is the format for findByIdAndUpdate
findByIdAndUpdate(id, update, options, callback)
You are not providing any update object. That's why it's not updating.
Try something like
Beer.findByIdAndUpdate(req.params.id, {name : 'updatedName'},...
Upvotes: 1