tag:blogger.com,1999:blog-6063627024520487734.post1499854822043104729..comments2022-12-10T21:52:37.106+08:00Comments on Jan Amoyo: MongoDB Transaction Across Multiple Documents using Async and Mongoosejramoyohttp://www.blogger.com/profile/04727621188639609013noreply@blogger.comBlogger2125tag:blogger.com,1999:blog-6063627024520487734.post-40938022375479085662014-07-22T23:47:45.127+08:002014-07-22T23:47:45.127+08:00Yes, you are correct, that is one caveat I failed ...Yes, you are correct, that is one caveat I failed to mentioned.<br /><br /><br />The errors I had in mind were more around data validation within Mongoose, but as you pointed out, the rollback itself can fail.<br /><br /><br />Unfortunately, I have no solution for that as of the moment other than retry the rollback as you suggested.jramoyohttp://www.jramoyo.comnoreply@blogger.comtag:blogger.com,1999:blog-6063627024520487734.post-22270358926843978272014-07-22T21:45:10.692+08:002014-07-22T21:45:10.692+08:00Thanks for this write-up. Async looks like a good ...Thanks for this write-up. Async looks like a good option to write cleaner code when you need to atomically write multiple documents.<br /><br />But what happens if the rollback doesn't succeed? I could imagine this situation:<br /><br />- value1 is inserted in database<br /><br />- value2 is inserted in database<br /><br />- Network connection to database goes down<br /><br />- Attempt to insert value3 results in an error, rollback function is called<br /><br />- Attempt to delete value1 results in error<br /><br />- Attempt to delete value2 results in error<br /><br />- Network connection to database comes back up<br /><br />Now the database is in an inconsistent state, something we wanted to avoid. To fix this sitution, I think you'd need to add a mechanism to retry the rollback. Are there other (better? easier?) ways to fix it though?jrullmannnoreply@blogger.com