app开发网站排行,网站改名 备案,dw如何制作自己的网站,深圳哪家公司需要网站建设的$count阶段用于统计管道中文档的数量。
语法
{ $count: string }string 是文档计数输出字段的名称。string必须是非空字符串#xff0c;不能以$开头#xff0c;也不能包含.字符。
$count阶段相当于下面$group$project聚合序列#xff1a;
db.co…$count阶段用于统计管道中文档的数量。
语法
{ $count: string }string 是文档计数输出字段的名称。string必须是非空字符串不能以$开头也不能包含.字符。
$count阶段相当于下面$group$project聚合序列
db.collection.aggregate( [{ $group: { _id: null, myCount: { $sum: 1 } } },{ $project: { _id: 0 } }
] )其中myCount是包含计数的输出字段。也可以为输出字段指定其他名称。
举例
scores的集合有以下文档
{ _id : 1, subject : History, score : 88 }
{ _id : 2, subject : History, score : 92 }
{ _id : 3, subject : History, score : 97 }
{ _id : 4, subject : History, score : 71 }
{ _id : 5, subject : History, score : 79 }
{ _id : 6, subject : History, score : 83 }下面的汇总操作分为两个阶段 $match阶段会排除分值小于或等于80的文档将分值大于80的文档传递到下一阶段。 $count阶段返回聚合管道中剩余文档的计数并将该值赋值给名为passing_scores的字段。
db.scores.aggregate([{$match: {score: {$gt: 80}}},{$count: passing_scores}]
)操作返回以下结果
{ passing_scores : 4 }