Skip to content

Instantly share code, notes, and snippets.

@fforbeck
Created March 18, 2013 22:08
Show Gist options
  • Save fforbeck/5191262 to your computer and use it in GitHub Desktop.
Save fforbeck/5191262 to your computer and use it in GitHub Desktop.
aggregator
db.website_performance.aggregate(
[
{
$group: {
_id: "$domain",
sum_impressions: {
$sum: "$impressions"
},
sum_bids: {
$sum: "$bids"
}
}
},
{
$project: {
ctr: {
$multiply: [
100,
{
$divide: [
"$sum_impressions",
"$sum_bids"
]
}
]
}
}
},
{
$sort: {
ctr: -1
}
},
{
$limit: 0
}
]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment