Student.findByIdAndUpdate(helper_id,{$push: {"favour": favour}});
Why do I use the above code, this function cannot be executed, but can be executed using the following code?
Student.findByIdAndUpdate(helper_id,{$push: {"favour": favour}}).exec()
But why do I use it directlyStudent.find()
AndStudent.findOne()
No need.exec()
Can it be carried out?
Please refer to Mongoose’s documentation.
1、findOneAndUpdate([query], [doc], [options], [callback])
Callback delivery is required before execution.
2. exec is the way to write promise instead of callback, which is the same as using callback.
For reference.
Love MongoDB! Have Fun!
–>Poke me<-please poke the left, it’s in April! Sign up quickly!
MongoDB Chinese Community Shenzhen User Conference Begins Registration! The great spirit of this forum will be ceremoniously introduced and delivered a speech at the conference. Applause here! ! !