Skip to content

Commit 083e18a

Browse files
committed
fix(transactions): fix sharded transaction error logic
Fixed the logic so that startTransaction will not error on sharded transactions on mongodb > 4.2.0
1 parent bcf6358 commit 083e18a

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

lib/core/sessions.js

+4-3
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ const resolveClusterTime = require('./topologies/shared').resolveClusterTime;
1818
const isSharded = require('./wireprotocol/shared').isSharded;
1919
const maxWireVersion = require('./utils').maxWireVersion;
2020

21-
const MAX_FOR_TRANSACTIONS = 7;
21+
const minWireVersionForShardedTransactions = 8;
2222

2323
function assertAlive(session, callback) {
2424
if (session.serverSession == null) {
@@ -191,8 +191,9 @@ class ClientSession extends EventEmitter {
191191

192192
const topologyMaxWireVersion = maxWireVersion(this.topology);
193193
if (
194-
isSharded(this.topology) ||
195-
(topologyMaxWireVersion != null && topologyMaxWireVersion < MAX_FOR_TRANSACTIONS)
194+
isSharded(this.topology) &&
195+
(topologyMaxWireVersion == null ||
196+
topologyMaxWireVersion < minWireVersionForShardedTransactions)
196197
) {
197198
throw new MongoError('Transactions are not supported on sharded clusters in MongoDB < 4.2.');
198199
}

test/functional/transactions_tests.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ describe('Transactions', function() {
7171

7272
describe('startTransaction', function() {
7373
it('should error if transactions are not supported', {
74-
metadata: { requires: { topology: ['sharded'], mongodb: '>4.0.0' } },
74+
metadata: { requires: { topology: ['sharded'], mongodb: '4.0.x' } },
7575
test: function(done) {
7676
const configuration = this.configuration;
7777
const client = configuration.newClient(configuration.writeConcernMax(), { poolSize: 1 });

0 commit comments

Comments
 (0)