3 var roomIds = db.troupes.find({ lcUri: { $in: [
4 'marionettejs/backbone.marionette',
5 'freecodecamp/freecodecamp',
11 'home-assistant/home-assistant'
13 }).map(function(f) { return f._id });
15 var a = db.chatmessages.aggregate([{
17 toTroupeId: { $in: roomIds },
18 sent: { $type: 'date' }
23 userId: '$fromUserId',
24 troupeId: '$toTroupeId',
26 firstSent: { $min: '$sent'},
27 lastSent: { $max: '$sent'},
33 duration: { $divide: [{ $subtract: ['$lastSent', '$firstSent']}, 86400000] }
38 totalActiveUserCount: { $sum: 1 },
39 firstSent: { $min: '$firstSent'},
40 lastSent: { $max: '$lastSent'},
41 avgDuration: { $avg: '$duration' }
47 totalActiveUserCount: 1,
48 totalDuration: { $divide: [{ $subtract: ['$lastSent', '$firstSent']}, 86400000] },
50 avgOverLifetime: { $divide: ['$avgDuration', { $divide: [{ $subtract: ['$lastSent', '$firstSent']}, 86400000] }] }
67 totalActiveUserCount: 1,
74 printjson(a.toArray());