Filtering vs Shaping Documents

MongoDB $match vs $project – When to Use Which?

Two key aggregation stages that beginners often confuse

By Sharanmeet Singh
Tags:MongoDBAggregation$match$project

MongoDB Query Generator

Generate MongoDB queries and aggregation pipelines

Try Generator

MongoDB $match vs $project

In the aggregation pipeline, two commonly used stages are $match and $project.


$match Example

{
  "$match": { "status": "active" }
}

Filters documents where status = active.


$project Example

{
  "$project": { "name": 1, "email": 1 }
}

Selects only the name and email fields.


Key Difference

  • $match filters documents
  • $project shapes the output fields

Tip: Always use $match early for better performance.