文档存储在以下字段中:
_id:
NumberofChildren: Integer
OwnsAHome: Boolean
Income: Integer
我需要使用聚合框架按子项的数量进行排序,所以输出是这样的:
Number of Children: 3
Number of People: some value, say 17
Number of People who own a home: some value less than 17 which is a sum of the number of true Booleans
Average income: some value
我将如何在MongoDB 中使用聚合来执行此操作,尤其是在计算 , 的次数Boolean OwnsAHome
方面true
?
谢谢!