This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var findNeighbours = function (spot, yearTag) { | |
var result = db.postcodes.aggregate([ | |
{ | |
$geoNear: | |
{ | |
near: spot, | |
distanceField: "distance", | |
num: 5, | |
spherical: true | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
db.hottestLocations.findOne() | |
{ | |
"_id": ObjectId("5629108c96be45aba9cb0c98"), | |
"Year": 2015, | |
"PostCode": "SL6 9UD", | |
"Location": [ | |
{ | |
"type": "Point", | |
"coordinates": [ | |
51.558455, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
db.homeSales.aggregate([ | |
{ | |
$sort: {amount: -1} | |
}, | |
{ | |
$group: | |
{ | |
_id: {$year: "$date"}, | |
priciestPostCode: {$first: "$address.postcode"} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
> db.homeSales.findOne() | |
{ | |
"_id": ObjectId("56005dd980c3678b19792b7f"), | |
"amount": 9000, | |
"date": ISODate("1996-09-19T00:00:00Z"), | |
"address": { | |
"nameOrNumber": 25, | |
"street": "NORFOLK PARK COTTAGES", | |
"town": "MAIDENHEAD", | |
"county": "WINDSOR AND MAIDENHEAD", |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"Year": 2015, | |
"PostCode": "SL6 9UD", | |
"Location": [ | |
{ | |
"type": "Point", | |
"coordinates": [ | |
51.558455, | |
-0.756023 | |
] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
db.homeSales.aggregate([ | |
{ | |
$sort: {amount: -1} | |
}, | |
{ | |
$group: | |
{ | |
_id: {$year: "$date"}, | |
priciestPostCode: {$first: "$address.postcode"} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"Year": 2012, | |
"hightToLowPriceGap": 2923000 | |
}, | |
{ | |
"Year": 2013, | |
"hightToLowPriceGap": 5092250 | |
}, | |
{ | |
"Year": 2014, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
db.annualHomePrices.aggregate([ | |
{$project: | |
{ | |
Year: "$year", | |
hightToLowPriceGap: { | |
$subtract: ["$highestPrice", "$lowestPrice"] | |
}, | |
_id: 0 | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
> db.annualHomePrices.findOne() | |
{ | |
"_id": ObjectId("560957ac29a5574d557d426d"), | |
"highestPrice": 1000000, | |
"lowestPrice": 12000, | |
"averagePrice": 114059, | |
"priceStdDev": 81540, | |
"year": 1995 | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
db.homeSales.aggregate([ | |
{ | |
$group: | |
{ | |
_id: {$year: "$date"}, | |
highestPrice: {$max: "$amount"}, | |
lowestPrice: {$min: "$amount"}, | |
averagePrice: {$avg: "$amount"}, | |
priceStdDev: {$stdDevPop: "$amount"} | |
} |