Welcome to our blog series "A Developer's Notes". In this series we write down anything peculiar related to web development we came across, and couldn't find anywhere else.
MongoDB transactions initiated by session.startTransaction() or session.withTransaction() fail independent of the result of the promise they return.
In case of session.withTransaction() and an error thrown by the function within, the function is retried infinitely (might not be like that in all cases though)!
npm mongodb v3.7.3 (official node.js driver)
Don't let MongoDB operations within the transaction fail with a conscious error like E11000 (duplicate key error) for example.
This behaviour might come from the composition of versions we're using and can be distinctive to us. We're not saying that this is a bug or anything close to a general issue. It might be though. We're just recording our finding.