mongoose的findByIdAndUpdate返回的不是最新的数据
 发布于 9 年前  作者 JerroldLee  11905 次预览  最后一次回复是 8 年前  来自 问答 

mongoose的findByIdAndUpdate方法不是返回更新后的最新数据吗?为什么我取出来的是旧的数据,事实上数据库中数据是更新了的

3 回复
gjc9620
A.findByIdAndUpdate(id, update, options, callback) // executes
A.findByIdAndUpdate(id, update, options)  // returns Query
A.findByIdAndUpdate(id, update, callback) // executes
A.findByIdAndUpdate(id, update)           // returns Query
A.findByIdAndUpdate()                     // returns Query

http://mongoosejs.com/docs/api.html#model_Model.findByIdAndUpdate

DiER-WANG

有一个属性 new,可以控制返回的数据,默认的是 false 返回旧数据 new: bool - true to return the modified document rather than the original. defaults to false