MongoDB 聚合 $count
聚合 $count
此聚合階段計算從前一階段傳遞過來的文件的總數。
示例
在本例中,我們使用的是從 聚合簡介 部分的示例資料載入的 "sample_restaurants" 資料庫。
db.restaurants.aggregate([
{
$match: { "cuisine": "Chinese" }
},
{
$count: "totalChinese"
}
])
自己動手試一試 »
這將把 $count
階段的文件數量作為名為“totalChinese”的欄位返回。