Filters the documents to pass only the documents that match the specified
condition(s) to the next pipeline stage.

@see http://docs.mongodb.org/manual/reference/operator/aggregation/match/
424071
public function match() : Stage\Match
    {
        $stage = new Stage\Match($this);
        $this->addStage($stage);

        return $stage;
    }
270988
def count_documents(self, filter={},  *args, **kwargs):
        
        result = self.collection.count_documents(filter, *args, **kwargs)
        return result
661036
public <E extends T> void filter (Collection<E> coll)
    {
        for (Iterator<E> itr = coll.iterator(); itr.hasNext(); ) {
            if (!isMatch(itr.next())) {
                itr.remove();
            }
        }
    }
1272001
public static Result filter(String path, Collection<NumberedInclude> includes, Collection<String> excludes, boolean allowPartialMatches) {
        includes = (includes == null ? Collections.<NumberedInclude> emptyList() : includes);
        excludes = (excludes == null ? Collections.<String> emptyList() : excludes);

        if (includes.isEmpty() && excludes.isEmpty()) {
            return INCLUDED;
        }

        if (Regex.simpleMatch(excludes, path)) {
            return EXCLUDED;
        }

        boolean exactIncludeMatch = false; // true if the current position was specifically mentioned
        boolean pathIsPrefixOfAnInclude = false; // true if potentially a sub scope can be included

        NumberedInclude matchedInclude = null;

        if (includes.isEmpty()) {
            // implied match anything
            exactIncludeMatch = true;
        }
        else {
            for (NumberedInclude filter : includes) {
                matchedInclude = filter;
                String include = filter.filter;

                // check for prefix matches as well to see if we need to zero in, something like: obj1.arr1.* or *.field
                // note, this does not work well with middle matches, like obj1.*.obj3
                if (include.charAt(0) == '*') {
                    if (Regex.simpleMatch(include, path)) {
                        exactIncludeMatch = true;
                        break;
                    }
//                    pathIsPrefixOfAnInclude = true;
//                    continue;
                }
                if (include.startsWith(path)) {
                    if (include.length() == path.length()) {
                        exactIncludeMatch = true;
                        break;
                    }
                    else if (include.length() > path.length() && include.charAt(path.length()) == '.') {
                        // This is mostly for the case that we are writing a document with a path like "a.b.c", we are
                        // starting to write the first field "a", and we have marked in the settings that we want to
                        // explicitly include the field "a.b". We don't want to skip writing field "a" in this case;
                        // Moreover, we want to include "a" because we know that "a.b" was explicitly included to be
                        // written, and we can't determine yet if "a.b" even exists at this point.
                        // The same logic applies for reading data. Make sure to read the "a" field even if it's not
                        // marked as included specifically. If we skip the "a" field at this point, we may skip the "b"
                        // field underneath it which is marked as explicitly included.
                        pathIsPrefixOfAnInclude = true;
                        continue;
                    }
                }
                if (Regex.simpleMatch(include, path)) {
                    exactIncludeMatch = true;
                    break;
                }
            }
        }

        // if match or part of the path (based on the passed param)
        if (exactIncludeMatch || (allowPartialMatches && pathIsPrefixOfAnInclude)) {
            return (matchedInclude != null ? new Result(true, matchedInclude.depth) : INCLUDED);
        }

        return EXCLUDED;
    }
590000
public Set<DOCUMENT> query(@NonNull Iterable<KEY> keys, @NonNull Predicate<? super DOCUMENT> filter) {
      return Streams.asParallelStream(keys)
                    .flatMap(key -> index.get(key).stream())
                    .map(documents::get)
                    .filter(filter)
                    .collect(Collectors.toSet());
   }
927099
public static <T> void addAll(Collection<T> pagingResults, Collection<T> paging, BooleanExpression<T> filter)
	{
		if (pagingResults == null || paging == null)
			return;

		if (filter != null)
		{
			for (T obj : paging)
			{
				if (filter.apply(obj))
					pagingResults.add(obj);
			}
		}
		else
		{
			// add independent of a filter
			for (T obj : paging)
			{
				pagingResults.add(obj);
			}
		}
	}
1200300
def filter_records(self, records):
        
        for record in records:
            try:
                filtered = self.filter_record(record)
                assert (filtered)
                # Quick tracking whether the sequence was modified
                if filtered.seq == record.seq:
                    self.passed_unchanged += 1
                else:
                    self.passed_changed += 1
                yield filtered
            except FailedFilter as e:
                self.failed += 1
                v = e.value
                if self.listener:
                    self.listener(
                        'failed_filter',
                        record,
                        filter_name=self.name,
                        value=v)
525623
def with(*conditions, &block)
      @filters ||= []

      @filters << {:negate => false, :filter => block} if block
      conditions.each do |condition|
        @filters << {:negate => false, :filter => condition}
      end
    end
724095
@SuppressWarnings("unchecked")
    public final Collection<T> filter(final Collection<T> c) {
        if (getRules() != null && getRules().length > 0) {
            // attempt to use the same concrete collection type
            // as is passed in..
            Collection<T> filtered;
            try {
                filtered = c.getClass().newInstance();
            } catch (InstantiationException | IllegalAccessException e) {
                filtered = new ArrayList<T>();
            }

            if (type == MATCH_ALL) {
                filtered.addAll(matchAll(c));
            } else {
                filtered.addAll(matchAny(c));
            }
            return filtered;
        }
        return c;
    }
1298483
protected CollectionMatch selectBestCollectionMatch(CollectionMatch previousMatch, CollectionMatch currentMatch) {

        CollectionMatch bestMatch = null;
        if (previousMatch == null) {
            bestMatch = currentMatch;
        } else if (previousMatch.isDenyMatchByOmission()) {
            bestMatch = previousMatch;
        } else if (currentMatch.isDenyMatchByOmission()) {
            bestMatch = currentMatch;
        } else if (previousMatch.isDenyMatch()) {
            bestMatch = previousMatch;
        } else if (currentMatch.isDenyMatch()) {
            bestMatch = currentMatch;
        } else if (previousMatch.isPermitMatch()) {
            bestMatch = previousMatch;
        } else if (currentMatch.isPermitMatch()) {
            bestMatch = currentMatch;
        } else if (previousMatch.isExactMatch()) {
            bestMatch = previousMatch;
        } else if (currentMatch.isExactMatch()) {
            bestMatch = currentMatch;
        } else if (previousMatch.isPathMatch() && previousMatch.getUrlPattern().length() >= currentMatch.getUrlPattern().length()) {
            bestMatch = previousMatch;
        } else {
            bestMatch = currentMatch;
        }
        return bestMatch;
    }
1296797
function (connectionName, collectionName, options, cb) {

      options = options || {};
      var connectionObject = connections[connectionName];
      var collection = connectionObject.collections[collectionName];

      // Find all matching documents
      collection.find(options, function (err, results) {
        if (err) return cb(err);
        cb(null, results);
      });
    }
681996
def scan(cls, filter_builder=None, **scan_filter):
        
        scan_kwargs = {'scan_filter': build_condition(scan_filter)}
        if filter_builder:
            cls._build_filter_expression(filter_builder, scan_kwargs)
        return ResultSet(cls, 'scan', scan_kwargs)
220827
function queryMatchesAfterIncluding(matches, includeClause) {
  if (!includeClause) {
    return matches;
  }

  const includeClauses = includeClause.split(',');
  matches = _.map(matches, match => {
    for (let i = 0; i < includeClauses.length; i++) {
      const paths = includeClauses[i].split('.');
      match = includePaths(match, paths);
    }
    return match;
  });

  return matches;
}
215383
def matches_conditions?(object, query)
        query[:guard] == false ||
        Array(if_condition).all? {|condition| evaluate_method(object, condition)} &&
        !Array(unless_condition).any? {|condition| evaluate_method(object, condition)}
      end
271773
public function filterConditions(
        array $conditions,
        string $matchType = CollectionUtility::MATCH_TYPE_LOOSE,
        $preserveKeys = false
    ): ArrayObjectInterface {
        return new static(CollectionUtility::filterWhere($this->isCollection() ? $this->data : [$this->data],
            $conditions, $matchType, $preserveKeys));
    }
1132441
def filter(self, node, condition):
        

        if not isinstance(node, Node):
            raise TypeError('not a node')

        for child in node:
            if condition(child):
                yield child
            for subchild in self.filter(child, condition):
                yield subchild
1049210
def previous(self, match, predicate=None, index=None):
        
        current = match.start
        while current > -1:
            previous_matches = self.ending(current)
            if previous_matches:
                return filter_index(previous_matches, predicate, index)
            current -= 1
        return filter_index(_BaseMatches._base(), predicate, index)