Probeer de volgende codeRefer - https://docs.mongodb.com/manual /referentie/operator/aggregatie/eq/
https://docs.mongodb.com/manual/reference/operator/ aggregatie/voorwaarde/
https://docs.mongodb.com/manual/reference/operator/ aggregatie/groep/
DB.aggregate([
{$project:
{
tag_id: '$tag_id',
unreadcount: { $cond: [ { $eq: [ '$unread', 'true' ] }, 1, 0 ] }
}},
{ $group: {
_id: '$tag_id',
unread: { $sum: '$unreadcount'},
}}
], function (err, results) {
console.log(results);
})