I have collection that contains documents with below schema. I want to filter/find all documents that contain the gender female and aggregate the sum of brainscore. I tried the
You have to use $match:
db['!all'].aggregate([ {$match: {'GENDER': 'F', 'DOB': { $gte: 19400801, $lte: 20131231 } } }, {$group: {_id: "$GENDER", totalscore:{ $sum: "$BRAINSCORE"}}} ])
Outputs:
{ "_id" : "F", "totalscore" : 109 }