Опитайте следния код Refer - https://docs.mongodb.com/manual /reference/operator/aggregation/eq/
https://docs.mongodb.com/manual/reference/operator/ aggregation/cond/
https://docs.mongodb.com/manual/reference/operator/ агрегиране/група/
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);
})