Documentation / @andrew_l/mongo-transaction / onMongoSessionCommitted
Function: onMongoSessionCommitted()
Call Signature
onMongoSessionCommitted<
T>(fn):OnMongoSessionCommittedResult<T>
Executes the provided function when the session ends with a committed transaction. Not called on rollback or abort.
⚠️ Registers a listener per call, so a retried callback runs it once per attempt. Inside withMongoTransaction prefer onCommitted().
Type Parameters
T
T
Parameters
fn
() => Awaitable<T>
Returns
OnMongoSessionCommittedResult<T>
Example
const { promise } = onMongoSessionCommitted(async () => {
console.info('Transaction committed successfully!');
return Math.random(); // Random value generated after commit
});
promise.then(result => {
if (result !== undefined) {
console.info('Handler result:', result); // e.g., Handler result: 0.07576196837476501
}
});Call Signature
onMongoSessionCommitted<
T>(session,fn):OnMongoSessionCommittedResult<T>
Executes the provided function when the session ends with a committed transaction. Not called on rollback or abort.
⚠️ Registers a listener per call, so a retried callback runs it once per attempt. Inside withMongoTransaction prefer onCommitted().
Type Parameters
T
T
Parameters
session
ClientSession
fn
() => Awaitable<T>
Returns
OnMongoSessionCommittedResult<T>
Example
const { promise } = onMongoSessionCommitted(async () => {
console.info('Transaction committed successfully!');
return Math.random(); // Random value generated after commit
});
promise.then(result => {
if (result !== undefined) {
console.info('Handler result:', result); // e.g., Handler result: 0.07576196837476501
}
});