Essayez le code suivantRefer - https://docs.mongodb.com/manual /reference/operator/aggregation/eq/
https://docs.mongodb.com/manual/reference/operator/ agrégation/cond/
https://docs.mongodb.com/manual/reference/operator/ agrégation/groupe/
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);
})