plexinc/papr

Can't use upsert inside transaction

Closed this issue ยท 4 comments

Is there any specific reason why the upsert method does not allow options?
I would like to pass my session into it but I can't.
I would assume it would accept the same options as update, right?

Screenshot 2024-01-17 at 13 58 05

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.

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?

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.

Makes sense! Thanks for the help!