I have a collection called Students. which has a field it contains the string value ie. Gryffindor, Hufflepuff, Ravenclaw, Slytherin
I am displaying the count of the students in each house
for that I'm doing something like this
G = Students.find({house:'Gryffindor'}).count();
H = Students.find({house:'Hufflepuff'}).count();
R = Students.find({house:'Ravenclaw'}).count();
S = Students.find({house:'Slytherin'}).count();
and displaying.
Is this the best practice or am I doing something wrong. ? Like is there a way that this could be done in a single query ?
Aucun commentaire:
Enregistrer un commentaire