Major - P3
The provided withTransaction and withSession helpers make running transactions very simple, but it's difficult to get the results of the operation back.
Both functions take a lambda as an argument that must return a Promise, but the functions don't pass through the value that the promise resolves to. This means that I need to create a wrapper function like this in order to get the return value:
It's not the end of the world, but it would be nice if these functions could just pass through the results.
As a Node.js user
I want a meaningful result from the withTransaction/withSession API
So that I can write robust handling code for the total result of the operations in the function passed to those APIs
- Breaking change The withTransaction API has returned the command result or "undefined" depending on the transaction outcome. It will now return the result of the function passed in by the user.
- Capture the result of the resolved promise from the user's withTransaction function.
- Return the captured value from the withTransaction API
- "" - for withSession
- Update typescript to automatically defined the return type from the type of the given function
- withTransaction should return the result of the function regardless of transaction outcome
- Both withSession/withTransaction should throw/reject if the function passed in throws/rejects
- Add typescript tests that demonstrate automatic return type calculation
- Update: https://www.mongodb.com/blog/post/quick-start-nodejs--mongodb--how-to-implement-transactions
- Annotate video / link to updated docs in video tutorial: https://www.youtube.com/watch?v=bdS03tgD2QQ&t=1046s&ab_channel=MongoDB
- Update API docs
- Add a note about this change to: https://www.mongodb.com/docs/drivers/node/current/fundamentals/transactions/
- Release Notes