diff --git a/lib/mongodb.js b/lib/mongodb.js index 85e67fcdf..9eb83a499 100644 --- a/lib/mongodb.js +++ b/lib/mongodb.js @@ -2349,23 +2349,17 @@ MongoDB.prototype.beginTransaction = function(isolationLevel, cb) { }; MongoDB.prototype.commit = function(tx, cb) { - tx.commitTransaction(function(err) { - tx.endSession(null, function(error) { - if (err) return cb(err); - if (error) return cb(error); - cb(); - }); - }); + tx.commitTransaction() + .then(() => tx.endSession()) + .then(() => cb()) + .catch((err) => cb(err)); }; MongoDB.prototype.rollback = function(tx, cb) { - tx.abortTransaction(function(err) { - tx.endSession(null, function(error) { - if (err) return cb(err); - if (error) return cb(error); - cb(); - }); - }); + tx.abortTransaction() + .then(() => tx.endSession()) + .then(() => cb()) + .catch((err) => cb(err)); }; function isInTransation(options) {