Mongo Currently does not the transaction in the sharded cluster when we are updating more than one document. In such cases how we should handle partial failures. It there any recommended pattern for these kinds of problems.
Asked
Active
Viewed 38 times
1 Answers
0
Sharded cluster transaction is a feature that will come in the upcoming MongoDB 4.2: Distributed Transactions.
For older MongoDB versions, you would need to simulate this behaviour using two-phase commit. There is a pattern for this in the MongoDB manual: Perform Two Phase Commits.
Basically the pattern is to have a special document that tracks the state of the transaction, with the transaction ID tracked in the individual documents involved in the transaction. Once all the necessary updates are successfully performed, you can mark the transaction as "done" and clean up all the metadata involved in the process.

kevinadi
- 13,365
- 3
- 33
- 49