[COMPASS-6249] Investigate changes in NODE-2014: Pass through results of given lambda in withTransaction and withSession Created: 26/Oct/22  Updated: 12/Jan/23  Resolved: 12/Jan/23

Status: Closed
Project: Compass
Component/s: None
Affects Version/s: None
Fix Version/s: No version

Type: Investigation Priority: Major - P3
Reporter: PM Bot Assignee: Unassigned
Resolution: Done Votes: 0
Labels: node-driver
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Depends
depends on NODE-2014 Pass through results of given lambda ... Closed
Related
related to MONGOSH-1358 Update to driver and bson v5.x Closed
Documentation Changes: Not Needed

 Description   

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.



 Comments   
Comment by Anna Henningsen [ 12/Jan/23 ]

Covered by MONGOSH-1358

Generated at Wed Feb 07 22:42:27 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.