lib/topologies/replset_state.js
function(readPreference, servers) {
  if (readPreference.tags == null) return servers;
  var filteredServers = [];
  var tagsArray = Array.isArray(readPreference.tags) ? readPreference.tags : [readPreference.tags];

  // Iterate over the tags
  for (var j = 0; j < tagsArray.length; j++) {
    var tags = tagsArray[j];

    // Iterate over all the servers
    for (var i = 0; i < servers.length; i++) {
      var serverTag = servers[i].lastIsMaster().tags || {};

      // Did we find the a matching server
      var found = true;
      // Check if the server is valid
      for (var name in tags) {
        if (serverTag[name] !== tags[name]) {
          found = false;
        }
      }

      // Add to candidate list
      if (found) {
        filteredServers.push(servers[i]);
      }
    }
  }

  // Returned filtered servers
  return filteredServers;
}
function(readPreference, servers) {
  if (readPreference.tags == null) return servers;
  var filteredServers = [];
  var tagsArray = Array.isArray(readPreference.tags) ? readPreference.tags : [readPreference.tags];

  // Iterate over the tags
  for (var j = 0; j < tagsArray.length; j++) {
    var tags = tagsArray[j];

    // Iterate over all the servers
    for (var i = 0; i < servers.length; i++) {
      var serverTag = servers[i].lastIsMaster().tags || {};

      // Did we find the a matching server
      var found = true;
      // Check if the server is valid
      for (var name in tags) {
        if (serverTag[name] !== tags[name]) {
          found = false;
        }
      }

      // Add to candidate list
      if (found) {
        filteredServers.push(servers[i]);
      }
    }
  }

  // Returned filtered servers
  return filteredServers;
}
function ( readPreference , servers ) { if ( readPreference . tags == null ) return servers ; var filteredServers = [ ] ; var tagsArray = Array . isArray ( readPreference . tags ) ? readPreference . tags : [ readPreference . tags ] ; // Iterate over the tags for ( var j = 0 ; j < tagsArray . length ; j ++ ) { var tags = tagsArray [ j ] ; // Iterate over all the servers for ( var i = 0 ; i < servers . length ; i ++ ) { var serverTag = servers [ i ] . lastIsMaster ( ) . tags || { } ; // Did we find the a matching server var found = true ; // Check if the server is valid for ( var name in tags ) { if ( serverTag [ name ] !== tags [ name ] ) { found = false ; } } // Add to candidate list if ( found ) { filteredServers . push ( servers [ i ] ) ; } } } // Returned filtered servers return filteredServers ; }
Filter serves by tags
Filter serves by tags