$count
noun
say it: “DOL-er KOWNT” /ˈdɑlər ˈkaʊnt/
A MongoDB aggregation stage that counts the documents reaching it and outputs one document with the total.
What does the $count stage do?
$count is an aggregation stage that counts the documents reaching it and hands on one document with that number, in a field you name. It goes after the stages that pick which documents count.
db.orders.aggregate([
{ $match: { status: "shipped" } },
{ $count: "shipped" }
]);
// [ { shipped: 197 } ]
In a sentence
- “$count "orders" handed on { orders: 197 }.”
- “The pipeline ends with $count, so the dashboard gets one number instead of a list.”
Level: Apprentice · More MongoDB terms at this level
Updated