文檔存儲與以下字段:如何計算布爾MongoDB中與聚合框架
_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
?
謝謝!
不要忘記添加到$項目你想每場以包含「fieldName:1」,否則$ project中唯一出現的將是_id字段和這個新的計算字段。 –
'{'$ group':{.... {count:{$ sum:{$ cond:[「$ close」,1,0]}}}} $ cond自$ 3.2版本開始工作 – eri