So I have this code:
db.collection.find( { sex: 'Male' } ).count()
And what I want to do is count both sex: 'Female'
instead of
db.collection.find( { sex: 'Male' } ).count() db.collection.find( { sex: 'Female' } ).count()
Is there a way to do this in a single query? Because I am generating a pie chart based on its length. Any help will be greatly appreciated.
1> Xiaozhi..:
db.collection.aggregate([ {"$group" : {_id:"$sex", count:{$sum:1}}} ])