diff --git a/lib/core/topologies/read_preference.js b/lib/core/topologies/read_preference.js index c383aa55f7..27a8a37dd0 100644 --- a/lib/core/topologies/read_preference.js +++ b/lib/core/topologies/read_preference.js @@ -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 }); } }