π―Match
Filter documents
The match stage is used to filter documents that will be used as input to the next stage in the pipeline. The filtered documents match one or more specified conditions.
One way to use the Match stage in a pipeline is to use the Aggregate
method in a IMongoCollection<T>
and chain the Match
method.
The following sample builds an aggregate with only one stage included. An aggregate with only one stage which happens to be a Match stage is actually equal to a simple find result with the same filter definitions. The sample filters User
documents having salary between 3500 and 5000.
Match with Project
The following sample adds a Match stage to filter Traveler
documents that have visited "Greece" exactly 3 times and projects the Id, Name, Age and VisitedCountries of each document. Notice that the match stage has been applied to array field elements using the $elemMatch operator.
Last updated