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 days: { $addToSet: { $dayOfYear: "$sent" } },
23 users: { $addToSet: "$fromUserId" },
29 days: { $size: '$days' },
30 uniqueUserCount: { $size: '$users' },
41 uniqueUserCount: { $gt: 3 }
56 public: '$troupe.sd.public',
57 totalUsers: '$troupe.userCount',
58 activeUsers: '$uniqueUserCount',
60 totalMessages: '$count'
64 print('uri,public,activeDays,totalMessages,activeUsers,totalUsers')
65 a.forEach(function(i) {
66 print(i.uri + ',' + i.public + ',' + i.activeDays + ',' + i.totalMessages + ',' + i.activeUsers + ',' + i.totalUsers)