3 query, fail on third query, but only rolling back to the second query, first query not rolling back
try { // FAWN START HERE const task = Fawn.Task(); const winner = new Winner({ type: req.body.type, coupon: req.body.coupon }); await task .save(Winner, winner) // FIRST QUERY SAVE .update(Transaction, { coupon: req.body.coupon, type: req.body.type, createdAt: query }, { // SECOND QUERY :UPDATE $set: { win: "1", status_trx: "1" } }) .update(Transaction, { // THIRD QUERY (I accidentally make this third query error) status_trx: "2", type: req.body.type, createdAt: query }, { $set: { win: "3", status_trx: {} // -> THIS SHOULD ONLY RECEIVE STRING type } }).options({ multi: true }); const result = await task.run({useMongoose: true}); console.log(JSON.stringify(result)); status = true; } catch (err) { console.log(err); // It throws mongodb error, but the first save is not rolling back } finally { res.send(true); }
Please help ! >.<
3 query, fail on third query, but only rolling back to the second query, first query not rolling back
try { // FAWN START HERE const task = Fawn.Task(); const winner = new Winner({ type: req.body.type, coupon: req.body.coupon }); await task .save(Winner, winner) // FIRST QUERY SAVE .update(Transaction, { coupon: req.body.coupon, type: req.body.type, createdAt: query }, { // SECOND QUERY :UPDATE $set: { win: "1", status_trx: "1" } }) .update(Transaction, { // THIRD QUERY (I accidentally make this third query error) status_trx: "2", type: req.body.type, createdAt: query }, { $set: { win: "3", status_trx: {} // -> THIS SHOULD ONLY RECEIVE STRING type } }).options({ multi: true }); const result = await task.run({useMongoose: true}); console.log(JSON.stringify(result)); status = true; } catch (err) { console.log(err); // It throws mongodb error, but the first save is not rolling back } finally { res.send(true); }