diff --git a/lib/core/sessions.js b/lib/core/sessions.js index 019e294e87..66a0580c2b 100644 --- a/lib/core/sessions.js +++ b/lib/core/sessions.js @@ -18,7 +18,7 @@ const resolveClusterTime = require('./topologies/shared').resolveClusterTime; const isSharded = require('./wireprotocol/shared').isSharded; const maxWireVersion = require('./utils').maxWireVersion; -const MAX_FOR_TRANSACTIONS = 7; +const minWireVersionForShardedTransactions = 8; function assertAlive(session, callback) { if (session.serverSession == null) { @@ -191,8 +191,9 @@ class ClientSession extends EventEmitter { const topologyMaxWireVersion = maxWireVersion(this.topology); if ( - isSharded(this.topology) || - (topologyMaxWireVersion != null && topologyMaxWireVersion < MAX_FOR_TRANSACTIONS) + isSharded(this.topology) && + (topologyMaxWireVersion == null || + topologyMaxWireVersion < minWireVersionForShardedTransactions) ) { throw new MongoError('Transactions are not supported on sharded clusters in MongoDB < 4.2.'); } diff --git a/test/functional/transactions_tests.js b/test/functional/transactions_tests.js index ada3d0170a..dd0b81d919 100644 --- a/test/functional/transactions_tests.js +++ b/test/functional/transactions_tests.js @@ -71,7 +71,7 @@ describe('Transactions', function() { describe('startTransaction', function() { it('should error if transactions are not supported', { - metadata: { requires: { topology: ['sharded'], mongodb: '>4.0.0' } }, + metadata: { requires: { topology: ['sharded'], mongodb: '4.0.x' } }, test: function(done) { const configuration = this.configuration; const client = configuration.newClient(configuration.writeConcernMax(), { poolSize: 1 });