search

Home  >  Q&A  >  body text

mongodb - mongoose's findByIdAndUpdate() cannot be executed?

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

高洛峰高洛峰2791 days ago892

reply all(1)I'll reply

  • 我想大声告诉你

    我想大声告诉你2017-05-02 09:27:59

    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! ! !

    reply
    0
  • Cancelreply