Skip to content

Instantly share code, notes, and snippets.

@danared
Created November 2, 2015 18:11
Show Gist options
  • Save danared/804fd74010cd629cfae5 to your computer and use it in GitHub Desktop.
Save danared/804fd74010cd629cfae5 to your computer and use it in GitHub Desktop.
db.homeSales.aggregate([
{
$group:
{
_id: {$year: "$date"},
higestPrice: {$max: "$amount"},
lowestPrice: {$min: "$amount"},
averagePrice: {$avg: "$amount"},
priceStdDev: {$stdDevPop: "$amount"}
}
},
{
$sort: {_id: 1}
},
{
$project:
{
_id: 1,
higestPrice: 1,
lowestPrice: 1,
averagePrice: {$trunc: "$averagePrice"},
priceStdDev: {$trunc: "$priceStdDev"}
}
}
])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment