mongoose-transact-utils
Version:
Helper methods for Mongoose and MongoDB transactions
10 lines (9 loc) • 449 B
TypeScript
import { ClientSession } from 'mongoose';
export declare type MutationCallback<T> = (session: ClientSession) => Promise<T>;
/**
* Runs the provided `mutations` callback within a transaction and commits the changes to the DB
* only when it has run successfully.
*
* @param mutations A callback which does DB writes and reads using the session.
*/
export declare function runInTransaction<T>(mutations: MutationCallback<T>): Promise<T>;