Richard
09/18/2022, 8:18 AMapi/register
endpoint
- which runs a multi-document transaction in my mongodb database (updateMany
)
The Issue I'm encountering:
If two calls to that endpoint are made quickly, the latter one fails because the former's transaction in mongoDB isn't done yet. (see screenshot)
(continues in thread)Richard
09/18/2022, 8:18 AMCommand failed (WriteConflict): WriteConflict error: this operation conflicted with another operation. Please retry your operation or multi-document transaction.)
Solution:
⢠One way I can think of is to just run a get
beforehand & compare the payload values to see if that execution is really necessary.
Would like to know from more experienced developers how we I should handle this though.Lars Ivar Igesund
09/18/2022, 8:27 AMRichard
09/18/2022, 8:43 AMLars Ivar Igesund
09/18/2022, 8:47 AMLars Ivar Igesund
09/18/2022, 8:49 AMRichard
09/18/2022, 8:51 AMRichard
09/18/2022, 8:52 AMRichard
09/18/2022, 2:10 PMRichard
09/18/2022, 2:54 PMThe session.withTransaction() helper handles:
Creating a transaction
Committing the transaction if it succeeds
Aborting the transaction if your operation throws
**Retrying in the event of a transient transaction error.**
Nurul
09/21/2022, 12:21 PM