Skip to content

Instantly share code, notes, and snippets.

@danared
Created November 2, 2015 18:14
Show Gist options
  • Save danared/63a08384b8e512645d91 to your computer and use it in GitHub Desktop.
Save danared/63a08384b8e512645d91 to your computer and use it in GitHub Desktop.
db.homeSales.aggregate([
{
$sort: {amount: -1}
},
{
$group:
{
_id: {$year: "$date"},
priciestPostCode: {$first: "$address.postcode"}
}
},
{
$lookup:
{
from: "postcodes",
localField: "priciestPostCode",
foreignField: "postcode",
as: "locationData"
}
},
{
$sort: {_id: -1}
},
{
$project:
{
_id: 0,
Year: "$_id",
PostCode: "$priciestPostCode",
Location: "$locationData.location"
}
}
])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment