Introduction
In MongoDB, the order of steps in a pipeline changes the final result. Each step works on the output of the previous one, so the sequence is important.
When you want to filter data before grouping it to reduce work.
When you need to sort data after filtering to get correct order.
When you want to add new fields before grouping or sorting.
When you want to limit results after sorting to get top items.