1 db.chatmessages.aggregate([
2 { $project: { t: '$toTroupeId' } },
3 { $group: { _id: '$t', s: { $sum: 1 } } },
6 ]).result.forEach(function(f) {
7 var t = db.troupes.findOne({ _id: f._id });
8 if(t.security === 'PUBLIC') {
9 print(t.uri, f.s, t.security)