You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Do you want to request a feature or report a bug?
Bug (or very unexpected behavior)
What is the current behavior?
// Find docsconstgroup=awaitGroup.findById(id).exec();constprofile=awaitProfile.findById(id2).exec();// edit docsgroup.name='foo';profile.name='bar';// Save the documentsawaitsession.withTransaction(()=>{awaitgroup.save({ session });awaitprofile.save({ session });});
When the second save encounters a TransientTransactionErrors, withTransaction retries the entire lambda. The problem is that while the first save gets rolled back, the group document still thinks that it has been saved. So the second time around, group.save() will think that there's nothing to save and will basically be a no-op. This is very hard to understand and debug.
What is the expected behavior?
Ideal would be that if the transaction fails, the state of the document is rolled back as well. This may be difficult.
Perhaps we can get away with talking about it more in the docs for transactions. I believe what is required right now is to move the entire code block above into the withTransaction lambda (the find, modification, and save). That way the documents are reset if the transaction fails.
What are the versions of Node.js, Mongoose and MongoDB you are using? Note that "latest" is not a version.
Node: 12.14.0
Mongoose: 5.9.6
MongoDB: 4.2.3
The text was updated successfully, but these errors were encountered:
Ah yes, that looks like a very similar issue. In that issue, you’d want to reset the doc that had the error. In this issue, you want to reset the object that had its own write “succeed”, but another action in the transaction failed. Depending on how the fix is implemented, it could be the same or a different fix.
Do you want to request a feature or report a bug?
Bug (or very unexpected behavior)
What is the current behavior?
When the second save encounters a
TransientTransactionErrors
,withTransaction
retries the entire lambda. The problem is that while the first save gets rolled back, thegroup
document still thinks that it has been saved. So the second time around,group.save()
will think that there's nothing to save and will basically be a no-op. This is very hard to understand and debug.What is the expected behavior?
Ideal would be that if the transaction fails, the state of the document is rolled back as well. This may be difficult.
Perhaps we can get away with talking about it more in the docs for transactions. I believe what is required right now is to move the entire code block above into the
withTransaction
lambda (the find, modification, and save). That way the documents are reset if the transaction fails.What are the versions of Node.js, Mongoose and MongoDB you are using? Note that "latest" is not a version.
Node: 12.14.0
Mongoose: 5.9.6
MongoDB: 4.2.3
The text was updated successfully, but these errors were encountered: