Use cases for updateOne over findOneAndUpdate in MongoDB
I think that
findOneAndUpdate
carries out an atomic operation, so I'm assuming thatupdateOne
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.
![Nick Pineda](https://i.stack.imgur.com/MCGFq.jpg?s=256&g=1)
Nick Pineda
Recent Computer Science Graduate From Brigham Young University.
Updated on July 23, 2021Comments
-
Nick Pineda almost 3 years
I think that
findOneAndUpdate
carries out an atomic operation, so I'm assuming thatupdateOne
does not.Why would you choose
updateOne
overfindOneAndUpdate
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.