e-oj / Fawn

Transactions for MongoDB (See the README)
https://www.npmjs.com/package/fawn
MIT License
485 stars 54 forks source link

Fawn not rolling back to the first query (i have 3 queries), Please help ! #82

Open fabiokounang opened 4 years ago

fabiokounang commented 4 years ago

so, i have 3 queries, i make the third query error on purpose, but it does not rolling back until the first query, it's just rolling back to the second query. Please help !

try {
    const task = Fawn.Task();
    const winner = new Winner({ type: req.body.type, coupon: req.body.coupon });    
    await task
      .save(Winner, winner)
      .update(Transaction, { coupon: req.body.coupon, type: req.body.type, createdAt: query }, {
        $set: {
          win: "1",
          status_trx: "1"
        }
      })
      .update(Transaction, {    
        status_trx: "2",
        type: req.body.type,
        createdAt: query
      },
      {
        $set: {
          win: "3",
          status_trx: "3"
        }
      }).options({ multi: true });
    const result = await task.run({useMongoose: true});
    console.log(JSON.stringify(result));
  } catch (err) {
    console.log(err); // it throw error but does not rolling back until the first query
  } finally {
    res.send(true);
  }