For example I have following collection:
db.names.find({})
{ \"_id\" : ObjectId(\"5768d9b4bc6f464899594570\"), \"name\"
If I understand correctly, you want the sum of loglevels against each name. shouldn't this help?
db.names.aggregate([{$group:{_id:{name:"$name",loglevel:"$loglevel"},sum:{$sum:1}}}])