Skip to content

hermesdj/mongoose-tx

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

Mongoose TX is a transaction helper for mongoose & mongodb

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published