MongoDB 聚合 $count
聚合 $count
此聚合阶段统计上一阶段传递的文档总数。
实例
在本例中,我们使用的是从聚合部分的示例数据加载的 "sample_restaurants" 数据库。
db.restaurants.aggregate([{$match: { "cuisine": "Chinese" }},{$count: "totalChinese"}])
这将返回 $count 阶段的文档数,作为一个名为 "totalChinese" 的字段。
此聚合阶段统计上一阶段传递的文档总数。
在本例中,我们使用的是从聚合部分的示例数据加载的 "sample_restaurants" 数据库。
db.restaurants.aggregate([{$match: { "cuisine": "Chinese" }},{$count: "totalChinese"}])
这将返回 $count 阶段的文档数,作为一个名为 "totalChinese" 的字段。