Update model with Mongoose, Express, NodeJS

后端 未结 5 2133
一向
一向 2020-12-23 22:15

I\'m trying to update an instantiated model (\'Place\' - I know it works from other routes) in a MongoDB and have spent a while trying to properly do so. I\'m also trying t

5条回答
  •  天涯浪人
    2020-12-23 22:42

    Now, i think you can do this :

    Place.findOneAndUpdate({name:req.params.name}, req.body, function (err, place) {
      res.send(place);
    });
    

    You can find by id too :

    Place.findOneAndUpdate({_id:req.params.id}, req.body, function (err, place) {
      res.send(place);
    });
    

提交回复
热议问题