I understand that MongoDB documentation advises against using Promise.all
with a transaction. However, I want to understand the exact reason behind this recommendation.
After researching various documents about the Node.js driver and how transactions work in the WiredTiger storage engine, I believe the reasons are as follows:
1. A single database connection cannot process parallel operations. Even if I use `Promise.all`, the Node.js driver will send requests to the server sequentially.
2. If I send requests sequentially and one query fails, subsequent requests won’t be sent to the MongoDB server. However, if I use `Promise.all`, the Node.js driver will still send all requests to the server in sequence. In this case, any queries sent after a failed query will result in an error because the transaction is already marked as inactive.
this happens because ‘Promise.all’ does not immediatly cancel remaining promises when one of them fails.
Are these assumptions correct? If not, could you clarify why Promise.all
should not be used with a MongoDB transaction?