lib/sdam/server_selectors.js
function tagSetReducer(readPreference, servers) {
  if (
    readPreference.tags == null ||
    (Array.isArray(readPreference.tags) && readPreference.tags.length === 0)
  ) {
    return servers;
  }

  for (let i = 0; i < readPreference.tags.length; ++i) {
    const tagSet = readPreference.tags[i];
    const serversMatchingTagset = servers.reduce((matched, server) => {
      if (tagSetMatch(tagSet, server.tags)) matched.push(server);
      return matched;
    }, []);

    if (serversMatchingTagset.length) {
      return serversMatchingTagset;
    }
  }

  return [];
}
function tagSetReducer(readPreference, servers) {
  if (
    readPreference.tags == null ||
    (Array.isArray(readPreference.tags) && readPreference.tags.length === 0)
  ) {
    return servers;
  }

  for (let i = 0; i < readPreference.tags.length; ++i) {
    const tagSet = readPreference.tags[i];
    const serversMatchingTagset = servers.reduce((matched, server) => {
      if (tagSetMatch(tagSet, server.tags)) matched.push(server);
      return matched;
    }, []);

    if (serversMatchingTagset.length) {
      return serversMatchingTagset;
    }
  }

  return [];
}
function tagSetReducer ( readPreference , servers ) { if ( readPreference . tags == null || ( Array . isArray ( readPreference . tags ) && readPreference . tags . length === 0 ) ) { return servers ; } for ( let i = 0 ; i < readPreference . tags . length ; ++ i ) { const tagSet = readPreference . tags [ i ] ; const serversMatchingTagset = servers . reduce ( ( matched , server ) => { if ( tagSetMatch ( tagSet , server . tags ) ) matched . push ( server ) ; return matched ; } , [ ] ) ; if ( serversMatchingTagset . length ) { return serversMatchingTagset ; } } return [ ] ; }
Reduces a set of server descriptions based on tags requested by the read preference

@param {ReadPreference} readPreference The read preference providing the requested tags
@param {ServerDescription[]} servers The list of server descriptions to reduce
@return {ServerDescription[]} The list of servers matching the requested tags
Reduces a set of server descriptions based on tags requested by the read preference