- Reference >
- Query, Update, Projection, and Aggregation Operators >
- $match (aggregation)
$match (aggregation)¶
-
$match¶ Provides a query-like interface to filter documents out of the aggregation pipeline. The
$matchdrops documents that do not match the condition from the aggregation pipeline, and it passes documents that match along the pipeline unaltered.The syntax passed to the
$matchis identical to the query syntax. Consider the following prototype form:The following example performs a simple field equality test:
This operation only returns documents where the
authorfield holds the valuedave. Consider the following example, which performs a range test:Here, all documents return when the
scorefield holds a value that is greater than 50 and less than or equal to 90.Note
Place the
$matchas early in the aggregation pipeline as possible. Because$matchlimits the total number of documents in the aggregation pipeline, earlier$matchoperations minimize the amount of later processing. If you place a$matchat the very beginning of a pipeline, the query can take advantage of indexes like any otherdb.collection.find()ordb.collection.findOne().Warning
You cannot use
$whereor geospatial operations in$matchqueries as part of the aggregation pipeline.