From 083e18a2491216df6841aff8596bfac3ed077c2e Mon Sep 17 00:00:00 2001 From: Dan Aprahamian Date: Tue, 30 Jul 2019 16:17:41 -0400 Subject: [PATCH] fix(transactions): fix sharded transaction error logic Fixed the logic so that startTransaction will not error on sharded transactions on mongodb > 4.2.0 --- lib/core/sessions.js | 7 ++++--- test/functional/transactions_tests.js | 2 +- 2 files changed, 5 insertions(+), 4 deletions(-) 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 });