Aggregation Pipeline Stages

  1. $match - Filter documents
  2. $group - Group by field
  3. $sort - Sort results
  4. $project - Select fields
  5. $lookup - Join collections
Blog.aggregate([
  { $match: { type: 'notes' } },
  { $sort: { createdAt: -1 } },
  { $limit: 10 }
]);