MongoDB $limit
Allow only the first number of documents to continue.
The current order matters. Limiting before sorting answers a different question from sorting the full stream and then limiting it.
Stages are the top-level steps in a pipeline. Each stage receives documents, changes the stream in one specific way, and passes its output to the next stage.
Course use: Exercises 03, 11, and Hard Mode 13.
Example pipeline syntax { $limit: 3 }
Continue learning Challenge 03: Rank the largest orders Return the three highest-value orders, largest first. Challenge 05: Build a store dispatch queue Find completed store orders, select the two lowest-value orders, then return `orderId`, `customerId`, and `total` in ascending total order. Challenge 17: Run parallel analyses For completed orders, return `byChannel` revenue summaries and the top two `byRegion` summaries in one document. Challenge 19: Rank customer lifetime leaders For completed orders, return the top three customers by revenue. Include `customerId`, `customerName`, `segment`, `revenue`, `orderCount`, and `averageOrder`. Challenge 20: Assemble an operations dashboard For completed orders, return one document with `regionalRevenue`, `largestOrders`, and `unitsByChannel`. Regional summaries need revenue and order count; largest orders need the top three compact order records; channel summaries need item units. Challenge 21: Build the commerce command report For completed orders, return one document with three arrays. `categoryPerformance` contains the top three categories with `category`, `revenue`, and `units`. `segmentPerformance` contains every customer segment with `segment`, `revenue`, `orderCount`, and `averageOrder`. `topOrder` contains the largest order with `orderId`, `region`, and `total`. Sort every report by revenue or total descending, using its name as the tie-breaker. Official MongoDB $limit documentation Browse all aggregation operators