【发布时间】:2015-12-16 10:08:13
【问题描述】:
我有一个名为 Student 的集合。
文档有一个字段house,其中包含一个字符串值,例如:'Gryffindor'、'Hufflepuff'、'Ravenclaw'、'Slytherin'
我正在显示每个房子的学生人数。
为此,我正在做这样的事情:
G = Students.find({ house: 'Gryffindor' }).count();
H = Students.find({ house: 'Hufflepuff' }).count();
R = Students.find({ house: 'Ravenclaw' }).count();
S = Students.find({ house: 'Slytherin' }).count();
并显示。
有没有一种方法可以在单个查询中完成?
【问题讨论】:
标签: mongodb meteor mongodb-query aggregation-framework