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 days: { $addToSet: { $dayOfYear: "$sent" } }
28 activeRooms: { $size: '$rooms' },
29 activeDays: { $size: '$days' },
34 activeRooms: '$activeRooms',
35 activeDays: '$activeDays',
41 activeRooms: '$_id.activeRooms',
42 activeDays: '$_id.activeDays',
52 print('activeRooms,activeDays,count')
53 a.forEach(function(i) {
54 print(i.activeRooms + ',' + i.activeDays + ',' + i.count)