3 var horizonTimestamp = Date.now() - 86400000 * 30;
5 function createIdForTimestampString(timestamp) {
6 var hexSeconds = Math.floor(timestamp/1000).toString(16);
8 while(hexSeconds.length < 8) {
9 hexSeconds = "0" + hexSeconds;
11 return ObjectId(hexSeconds + "0000000000000000");
14 var a = db.chatmessages.aggregate([{
16 _id: { $gt: createIdForTimestampString(horizonTimestamp) },
17 sent: { $type: 'date' }
22 rooms: { $addToSet: "$toTroupeId" },
23 totalMessages: { $sum: 1 },
24 days: { $addToSet: { $dayOfYear: "$sent" } }
29 activeRooms: { $size: '$rooms' },
30 activeDays: { $size: '$days' },
31 totalMessages: '$totalMessages'
35 print('activeRooms,activeRooms,activeDays,totalMessages')
36 a.forEach(function(i) {
37 print(i.userId + ',' + i.activeRooms + ',' + i.activeDays + ',' + i.totalMessages)