Advertisement
Guest User

Untitled

a guest
Jun 18th, 2019
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.43 KB | None | 0 0
  1. const session = await mongoose.startSession();
  2. session.startTransaction();
  3. const opts = { session, new: true };
  4. tableModel = MYMODEL.(data);
  5. tableModel.save(async function(err, response) {
  6. if (err) return handleError(err, res);
  7. else {
  8. try {
  9. console.log('Mongo success');
  10. await session.abortTransaction();
  11. session.endSession();
  12. console.log("rolled back")
  13. }
  14. catch(e) {
  15. next(e)
  16. }
  17. }
  18. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement