Aggregation Stages
Explore key MongoDB aggregation pipeline stages—$match, $group, $sort, and $project—used for filtering, grouping, sorting, and reshaping data to perform complex data analysis and transformation.
We'll cover the following...
We'll cover the following...
MongoDB offers some keywords to add stages in our pipelines to perform required actions. Let’s see each one in detail.
The $match stage
It filters the documents and is very similar to the .find() method. Here's an example used to filter documents in the orders collection to include only shipped orders.
Explanation: In line 1, we directly specify that this query needs to be executed via the aggregation pipeline: db.orders.aggregate. Here, $match tells MongoDB to only include documents where the status field is exactly ...