在 是返回 的文件。如果要返回新的,更新的文档,则必须传递一个附加参数:new
属性设置为的对象true
。
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);
});