Use cases for updateOne over findOneAndUpdate in MongoDB

24,470

I think that findOneAndUpdate carries out an atomic operation, so I'm assuming that updateOne does not.

Why are you assuming that?

findOneAndUpdate returns a document whereas updateOne does not (it just returns the _id if it has created a new document).

I think that's the main difference. So the use case of updateOne is when you don't need the document and want to save a bit of time and bandwidth.

Share:
24,470
Nick Pineda
Author by

Nick Pineda

Recent Computer Science Graduate From Brigham Young University.

Updated on July 23, 2021

Comments

  • Nick Pineda
    Nick Pineda almost 3 years

    I think that findOneAndUpdate carries out an atomic operation, so I'm assuming that updateOne does not.

    Why would you choose updateOne over findOneAndUpdate and avoid an atomic operation and have to spend extra time checking if the updates were atomic?

    I would appreciate some insight or a use case.