code: function resolveReadPreference(options, sources) {
    options = options || {};
    sources = 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) {
      // 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;
      }
    }
  
    // do we even have a read preference?
    if (readPreference == null) {
      return null;
    }
  
    // now attempt to convert the read preference if necessary
    if (typeof readPreference === 'string') {
      readPreference = new ReadPreference(readPreference);
    } else if (
      readPreference &&
      !(readPreference instanceof ReadPreference) &&
      typeof readPreference === 'object'
    ) {
      const mode = readPreference.mode || readPreference.preference;
      if (mode && typeof mode === 'string') {
        readPreference = new ReadPreference(mode, readPreference.tags, {
          maxStalenessSeconds: readPreference.maxStalenessSeconds
        });
      }
    } else if (!(readPreference instanceof ReadPreference)) {
      throw new TypeError('Invalid read preference: ' + readPreference);
    }
  
    return readPreference;
  }
docs: Resolves a read preference based on well-defined inheritance rules. This method will not only
  determine the read preference (if there is one), but will also ensure the returned value is a
  properly constructed instance of `ReadPreference`.
  
  @param {Object} options The options passed into the method, potentially containing a read preference
  @param {Object} sources Sources from which we can inherit a read preference
  @returns {(ReadPreference|null)} The resolved read preference