Aggregation Pipeline
noun
say it: “ag-rih-GAY-shun PYPE-lyne” /ˌæɡrɪˈɡeɪʃən ˈpaɪplaɪn/
A list of steps in MongoDB that documents pass through in order, each filtering, reshaping or summarizing them, to build results such as reports.
What is Aggregation Pipeline?
The aggregation pipeline processes documents through stages, like $match then $group then $sort, to filter, reshape and summarize data, similar to SQL's GROUP BY and JOIN.
db.orders.aggregate([
{ $match: { status: 'paid' } },
{ $group: { _id: '$customerId', total: { $sum: '$amount' } } },
{ $sort: { total: -1 } }
])
In a sentence
- “The monthly report is one aggregation pipeline: $match, $group, $sort.”
- “An aggregation pipeline runs inside the database, so only the results travel to the app.”
Level: Journeyman · More MongoDB terms at this level
Updated