Code QuizIntermediate

Pipeline structure and stage execution order

Aggregation stages run in the exact order you list them, so misordering $limit and $sort silently returns the wrong results.

Codejavascript
// Goal: get the 5 most expensive products
db.products.aggregate([
  { $limit: 5 },
  { $sort: { price: -1 } }
]);

This pipeline is supposed to return the 5 most expensive products, but it doesn't. What is the bug?