diff --git a/lib/operations/execute_operation.js b/lib/operations/execute_operation.js index bef633758b..b6276f3ddb 100644 --- a/lib/operations/execute_operation.js +++ b/lib/operations/execute_operation.js @@ -132,6 +132,11 @@ function executeWithServerSelection(topology, operation, callback) { return; } + const serverSelectionOptions = { + readPreference, + session: operation.session + }; + function callbackWithRetry(err, result) { if (err == null) { return callback(null, result); @@ -142,7 +147,7 @@ function executeWithServerSelection(topology, operation, callback) { } // select a new server, and attempt to retry the operation - topology.selectServer(readPreference, (err, server) => { + topology.selectServer(serverSelectionOptions, (err, server) => { if (err || !supportsRetryableReads(server)) { callback(err, null); return; @@ -153,7 +158,7 @@ function executeWithServerSelection(topology, operation, callback) { } // select a server, and execute the operation against it - topology.selectServer(readPreference, (err, server) => { + topology.selectServer(serverSelectionOptions, (err, server) => { if (err) { callback(err, null); return;