MongoDB Tutorial 0/120 lessons ~6 min read Lesson 51
Sort Stage
$sort orders the pipeline output.
Course progress0%
Focus
2 guided sections
Practice signal
Concept-first lesson
Career prep
Foundation builder
Introduction
$sort orders the pipeline output. Place it after filtering to minimize what gets sorted. Combined with $limit, the optimizer can do a 'top-N' that never holds the full result.
Syntax reference
js
{ $sort: { total: -1 } }
Ready to mark this lesson complete?Track your journey across the entire course.