跳到主要内容
CNode

mongoose的findByIdAndUpdate返回的不是最新的数据

问答
JJerroldLee发布于 10 年前最后回复 9 年前
3121940

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

查看回复

回复 (3)

D
DiER-WANG#39 年前

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

G
gjc9620#110 年前
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

参与回复

登录后即可参与回复。登录