您好, 欢迎来到 !    登录 | 注册 | | 设为首页 | 收藏本站

mongoose:findOneAndUpdate不返回更新的文档

mongoose:findOneAndUpdate不返回更新的文档

在 是返回 的文件。如果要返回新的,更新的文档,则必须传递一个附加参数:new属性设置为的对象true

mongoose文档中

Model.findOneAndUpdate(conditions, update, options, (error, doc) => {
  // error: any errors that occurred
  // doc: the document before updates are applied if `new: false`, or

after updates if new = true });

传递{new: true}如果你想更新的结果的doc变量:

//                                                         V--- THIS WAS ADDED
Cat.findOneAndUpdate({age: 17}, {$set:{name:"Naomi"}}, {new: true}, (err, doc) => {
    if (err) {
        console.log("Something wrong when updating data!");
    }

    console.log(doc);
});
mongodb 2022/1/1 18:13:52 有722人围观

撰写回答


你尚未登录,登录后可以

和开发者交流问题的细节

关注并接收问题和回答的更新提醒

参与内容的编辑和改进,让解决方法与时俱进

请先登录

推荐问题


联系我
置顶