Skip to content

Instantly share code, notes, and snippets.

@fforbeck
Created May 9, 2013 14:36
Show Gist options
  • Save fforbeck/5547834 to your computer and use it in GitHub Desktop.
Save fforbeck/5547834 to your computer and use it in GitHub Desktop.
db.website_performance.aggregate(
[
{
$match : { 'domain' : { $in: []} }
},
{
$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