mongodb - mongoose 的 findByIdAndUpdate() 不能执行?
高洛峰
高洛峰 2017-05-02 09:25:59
0
1
860

Student.findByIdAndUpdate(helper_id,{$push: {"favour": favour}});

为什么我使用上面的代码,该函数不能被执行,使用下面的代码却能执行?

Student.findByIdAndUpdate(helper_id,{$push: {"favour": favour}}).exec()

但是为什么我直接使用 Student.find()Student.findOne(), 不需要 .exec() 也能执行?

高洛峰
高洛峰

拥有18年软件开发和IT教学经验。曾任多家上市公司技术总监、架构师、项目经理、高级软件工程师等职务。 网络人气名人讲师,...

reply all(1)
我想大声告诉你

Please refer to Mongoose’s documentation

1. findOneAndUpdate([query], [doc], [options], [callback])

It will only be executed if callback is passed.

2. exec is the way of writing promise, replacing callback, and has the same effect as using callback.

For reference.

Love MongoDB! Have Fun!


-->Poke me<--Please poke me on the left, it’s April! Sign up now!

Registration for the MongoDB Chinese Community Shenzhen User Conference has begun! The master of this forum will make a grand appearance at the conference and deliver a speech. There is applause here! ! !

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!