mongoose-transact-utils
Helper methods for Mongoose and MongoDB transactions (Check out this medium post to know more about it).
The library comes with @types for Typescript users.
Installation
npm i mongoose-transact-utils
OR
yarn add mongoose-transact-utils
API Reference and Examples
A simple use case for transaction
const runInTransaction = ; const User = ; // any queries or write you want to do using transactionasync { // runInTransction catches any error in the callback to abort the transaction session // and then rethrows the error for you to handle the reporting await ; console;}; { const userA = await User; const userB = await User; userAfriends; userBfriends; await userA; await userB;}
Contributing
We are more than happy to accept contributions to this project in form of feedback, bug reports and pull requests.
References:
- https://mongoosejs.com/docs/transactions.html
- https://docs.mongodb.com/manual/core/write-operations-atomicity/
- NPM Package
- Medium Post
Contributors
- Soumyajit @drenther
- Sharad @csharad
- Nitish @nitish-mehta
- CashPositive