Skip to content

Commit

Permalink
fix: ReadPreference maxStalenessSeconds from options
Browse files Browse the repository at this point in the history
  • Loading branch information
Thomas Reggi authored Jul 29, 2020
1 parent 53cbdb0 commit 72a743d
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions lib/core/topologies/read_preference.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,20 +91,18 @@ const VALID_MODES = [
* @return {ReadPreference}
*/
ReadPreference.fromOptions = function(options) {
if (!options) return null;
const readPreference = options.readPreference;
if (readPreference == null) return null;
const readPreferenceTags = options.readPreferenceTags;

if (readPreference == null) {
return null;
}

const maxStalenessSeconds = options.maxStalenessSeconds;
if (typeof readPreference === 'string') {
return new ReadPreference(readPreference, readPreferenceTags);
} else if (!(readPreference instanceof ReadPreference) && typeof readPreference === 'object') {
const mode = readPreference.mode || readPreference.preference;
if (mode && typeof mode === 'string') {
return new ReadPreference(mode, readPreference.tags, {
maxStalenessSeconds: readPreference.maxStalenessSeconds
maxStalenessSeconds: readPreference.maxStalenessSeconds || maxStalenessSeconds
});
}
}
Expand Down

0 comments on commit 72a743d

Please sign in to comment.