From 568b12be535e8bcbfa00db481c0d1cee6b468a00 Mon Sep 17 00:00:00 2001 From: Vincent Vandenschrick Date: Wed, 1 Jul 2026 15:32:15 +0200 Subject: [PATCH] fix: #900 replace callback implementation by the promise one Signed-off-by: Vincent Vandenschrick --- lib/mongodb.js | 22 ++++++++-------------- 1 file changed, 8 insertions(+), 14 deletions(-) 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) {