3 var month = new Date(Date.now() - 86400000 * 31)
5 var roomId = db.troupes.findOne({ lcUri: 'openai/gym' })._id;
7 var a = db.chatmessages.aggregate([
8 { $match: { sent: { $gt: month }, toTroupeId: roomId } },
9 { $project: { t: '$fromUserId' } },
10 { $group: { _id: '$t', s: { $sum: 1 } } },
14 bucket: { $cond: [{ $lte: ["$s", 5] }, "1-5",
15 { $cond: [{ $lte: ["$s", 10] }, "5-10", "10+"]}
19 { $group: { _id: '$bucket', count: { $sum: 1 } } },
22 a.forEach(function(i) {
23 print(i._id + ',' + i.count)