Skip to content

Commit

Permalink
feat(read-preference): add transaction to inheritance rules
Browse files Browse the repository at this point in the history
  • Loading branch information
mbroadst committed Jun 19, 2018
1 parent 7530405 commit 18ca41d
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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 });
}
Expand Down

0 comments on commit 18ca41d

Please sign in to comment.