Skip to content

Instantly share code, notes, and snippets.

@pcorey
Last active January 24, 2016 14:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pcorey/0843081b858dd43b6d81 to your computer and use it in GitHub Desktop.
Save pcorey/0843081b858dd43b6d81 to your computer and use it in GitHub Desktop.
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