为什么会这样?
在 默认情况下 是返回 原来的,不变 的文件。如果要返回新的,更新的文档,则必须传递一个附加参数:
new属性设置为的对象
true。
从mongoose文档中:
Query#findOneAndUpdate
Model.findoneAndUpdate(conditions, update, options, (error, doc) => { // error: any errors that occurred // doc: the document before updates are applied if `new: false`, orafter updates if
new = true
});可用选项
new:bool-如果为 true ,则返回 修改后的 文档而不是原始文档。 默认为false (在4.0中更改)
解
传递
{new: true}如果你想更新的结果的doc变量:
// V--- THIS WAS ADDEDCat.findoneAndUpdate({age: 17}, {$set:{name:"Naomi"}}, {new: true}, (err, doc) => { if (err) { console.log("Something wrong when updating data!"); } console.log(doc);});


