-
Type: Improvement
-
Resolution: Fixed
-
Priority: Major - P3
-
Affects Version/s: Not Applicable
-
Component/s: Core, Sessions, Transactions
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:
runTransaction(writeFunc) { let writeResults = null; const txnFunc = session => ( writeFunc(session) .then((results) => { writeResults = results; }) ); return this.client.withSession(session => session.withTransaction(txnFunc))) .then(() => { return writeResults; }); }
It's not the end of the world, but it would be nice if these functions could just pass through the results.
Use Case
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
User Impact
- 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.
Dependencies
- None
Unknowns
- None
Acceptance Criteria
Implementation Requirements
- 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
Testing Requirements
- 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
Documentation Requirements
- 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
Follow Up Requirements
- None
- is depended on by
-
COMPASS-6249 Investigate changes in NODE-2014: Pass through results of given lambda in withTransaction and withSession
- Closed
- is related to
-
NODE-4108 session.withTransaction has wrong return type
- Closed
-
NODE-4961 commitTransaction and abortTransaction return command result
- Closed
-
NODE-5592 Fix return type of withTransaction
- Closed
-
DRIVERS-2680 Clarify withTransaction callback return value semantics
- Ready for Work
- related to
-
NODE-5402 Wrong TypeScript return type for session.withTransaction
- Closed
- links to
- mentioned in
-
Page Loading...