Skip to content

Commit

Permalink
fix(utils): restructure inheritance rules for read preferences
Browse files Browse the repository at this point in the history
  • Loading branch information
mbroadst committed Jun 19, 2018
1 parent a649e35 commit 6a7dac1
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -517,15 +517,16 @@ function resolveReadPreference(options, sources) {
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...
// The transaction’s read preference MUST override all other user configurable read preferences.
readPreference = session.transaction.options.readPreference;
} else if (coll && coll.s.readPreference) {
readPreference = coll.s.readPreference;
} else if (db && db.s.readPreference) {
readPreference = db.s.readPreference;
} else if (defaultReadPreference) {
readPreference = defaultReadPreference;
} else {
if (defaultReadPreference) {
readPreference = defaultReadPreference;
} else if (coll && coll.s.readPreference) {
readPreference = coll.s.readPreference;
} else if (db && db.s.readPreference) {
readPreference = db.s.readPreference;
}
}

// do we even have a read preference?
Expand Down

0 comments on commit 6a7dac1

Please sign in to comment.