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()
?
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! ! !