MongoDB 8 · Aggregation
Filter, sort and limit
Run $match early so the pipeline processes fewer documents.
db.orders.aggregate([
{ $match: { status: "paid" } },
{ $sort: { amount: -1 } },
{ $limit: 5 }
])
Official MongoDB 8 documentation
MongoDB 8 · Aggregation
Run $match early so the pipeline processes fewer documents.
db.orders.aggregate([
{ $match: { status: "paid" } },
{ $sort: { amount: -1 } },
{ $limit: 5 }
])
Official MongoDB 8 documentation
Was this page helpful?