mongoose-tx

1.0.1 • Public • Published

Mongoose TX

Build Status NPM

Mongoose tx is a transaction helper that runs transaction with retry and commit with retry according to the Mongodb documentation

Credits

Took a lot of inspiration from the quite promising mongoose ACID library you can find here :

Mongoose ACID

required

nodejs >= 7.6 | mongoose >= 5.2 | mongodb >= 4.0

usage

const Tx = require('mongoose-tx');
await Tx( async (session) => {
    await People.findOneAndUpdate({ name: 'Tx' },{ $inc: { balance: 30 } },{ session });
    await Account.findOneAndUpdate({ name: 'Blank'},{ $inc: { balance: -30 } },{ session });
    // ... 
});
const app = new Koa();
app.use(Tx.middleware());
app.use(async (ctx) => {
    await ctx.tx(async (session) => {
      
    });
})

test

npm test

Package Sidebar

Install

npm i mongoose-tx

Weekly Downloads

1

Version

1.0.1

License

MIT

Unpacked Size

8.44 kB

Total Files

7

Last publish

Collaborators

  • dallardj