Skip to content

Instantly share code, notes, and snippets.

@pcorey pcorey/abTest.js

Last active Jan 24, 2016
Embed
What would you like to do?
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
You can’t perform that action at this time.