【问题标题】:i'm getting an error while updating a targeted article我在更新目标文章时遇到错误
【发布时间】:2021-12-08 19:12:26
【问题描述】:

我正在尝试创建一个简单的 RestAPI,当我使用放置或更新一个 perticualr 元素时,它并没有更新任何东西。我使用邮递员来更新它。

    .put(function(req, res){

  Article.updateOne(
    {title: req.params.articleTitle},
    {title: req.body.title, content: req.body.content},
    {overwrite: true},
    function(err){
      if (!err){
        res.send("Successfully updated the content of the selected article.");
      }else{
        res.send(err);
      }
    }
    );
});

【问题讨论】:

    标签: node.js mongodb postman rest


    【解决方案1】:

    删除{overwrite: true} 行,您的代码就可以工作了。

    P.S:根据https://mongoosejs.com/docs/deprecations.html#update,您不应该在 updateOne 中使用overwrite 选项

    【讨论】:

      猜你喜欢
      • 2020-09-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-11-26
      • 2019-11-04
      • 1970-01-01
      相关资源
      最近更新 更多