Can't use upsert inside transaction
Closed this issue ยท 4 comments
MarceloPeresToi commented
joshuat commented
This is definitely something that could be improved - until this is done, though, you should be able to use model.findOneAndUpdate
with { upsert: true }
in the options to achieve the same functionality.
MarceloPeresToi commented
Oh, that's right!
My first instinct was to try the updateOne
method, but it doesn't accept the upsert option.
I didn't realise there was a findOneAndUpdate
. Thanks!
BTW, what's the difference between findOneAndUpdate
and updateOne
?
joshuat commented
findOneAndUpdate
does a find operation and updates the record, returning a document - updateOne
only does an update operation and returns the update result.
The upsert
method is just a wrapper around findOneAndUpdate
with the upsert
option preset.
MarceloPeresToi commented
Makes sense! Thanks for the help!