Multi-Document Transactions not Working using MongoDB Atlas

I contacted the MongoDB Support and it turned out that this is a known issue:

We are currently aware of an issue with the M0 Free Tier clusters whereby multi-statement transactions timeout with an error. This should be fixed with the rollout of MongoDB version 4.0.5. In the meantime, if you require this feature urgently, I would recommend that you upgrade your cluster to an M10+ cluster.

So the issue occurs because I am using the free tier. But the bug will hopefully be fixed with the MongoDB 4.0.5 release.

UPDATE

As my database runs now on version 4.0.5, the problem is fixed. So it wasn't necessarily a issue with the code.


Try adding .session(session) to each Query

const doc = await Schema2.findById(item.someId).session(session)

https://mongoosejs.com/docs/api.html#query_Query-session