Return a final count after filters and transforms.
Section: Advanced stages
Count pipeline output
javascript
javascript
db.orders.aggregate([
{ $match: { status: "paid" } },
{ $count: "paid_orders" }
])Explanation
`$count` is a concise finishing stage for reporting queries.
Learn the surrounding workflow
Compare similar commands or jump into common fixes when this command is part of a bigger troubleshooting path.
Related commands
Same sheet · prioritizing Advanced stages
Run multiple result sets with $facet
Produce multiple related aggregations in one pipeline.
Join with another collection
Use `$lookup` for collection-to-collection joins.