mongodb - mongoose's findByIdAndUpdate() cannot be executed?
高洛峰
高洛峰 2017-05-02 09:25:59
0
1
875

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

Why can’t the function be executed when I use the above code, but can it be executed when using the following code?

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

But why do I use Student.find() and Student.findOne() directly and it can be executed without .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