Last active
January 24, 2016 14:47
-
-
Save pcorey/0843081b858dd43b6d81 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var groups = [ | |
{ | |
query: {group: "A", createdAt: {$gte: ISODate("2016-01-01 05:00:00.000Z")}} | |
}, | |
{ | |
query: {group: "B", createdAt: {$gte: ISODate("2016-01-01 05:00:00.000Z")}} | |
} | |
]; | |
groups.map(function(group, index) { | |
group.cursor = db.users.find(group.query); | |
group.count = group.cursor.count(); | |
group.userIds = []; | |
while (group.cursor.hasNext()) { | |
group.userIds.push(group.cursor.next()._id); | |
} | |
group.interactions = db.interactions.find({ | |
userId: {$in: group.userIds} | |
}).count(); | |
print([ | |
"Group " + index + ":", | |
"Total users: " + group.count, | |
"Total interactions: " + group.interactions, | |
"Interactions/user: " + group.interactions/group.count | |
].join("\n")); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment