1.0.1 • Published 5 years ago

mongoose-tx v1.0.1

Weekly downloads
8
License
MIT
Repository
github
Last release
5 years ago

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