diff --git a/lib/utils.js b/lib/utils.js index c716753ddc..a5ce893b2e 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -511,10 +511,15 @@ function resolveReadPreference(options, sources) { const db = sources.db; const coll = sources.collection; const defaultReadPreference = sources.default; + const session = options.session; let readPreference; if (options.readPreference) { readPreference = options.readPreference; + } else if (session && session.inTransaction() && session.transaction.options.readPreference) { + // From transactions spec: If the user supplies an explicit readConcern via a method + // option, however, drivers MUST apply the readConcern... + readPreference = session.transaction.options.readPreference; } else if (coll && coll.s.readPreference) { readPreference = coll.s.readPreference; } else if (db && db.s.readPreference) { @@ -583,20 +588,18 @@ function decorateWithCollation(command, target, options) { } } -function decorateWithReadConcern(command, coll, options) { +/** + * Applies a read concern to a given command. + * + * @param {object} command the command on which to apply the read concern + * @param {Collection} [target] the parent collection of the operation calling this method + */ +function decorateWithReadConcern(command, coll) { let readConcern = Object.assign({}, command.readConcern || {}); if (coll.s.readConcern) { Object.assign(readConcern, coll.s.readConcern); } - if ( - options.session && - options.session.supports.causalConsistency && - options.session.operationTime - ) { - Object.assign(readConcern, { afterClusterTime: options.session.operationTime }); - } - if (Object.keys(readConcern).length > 0) { Object.assign(command, { readConcern: readConcern }); }