Skip to content

Instantly share code, notes, and snippets.

var findNeighbours = function (spot, yearTag) {
var result = db.postcodes.aggregate([
{
$geoNear:
{
near: spot,
distanceField: "distance",
num: 5,
spherical: true
}
db.hottestLocations.findOne()
{
"_id": ObjectId("5629108c96be45aba9cb0c98"),
"Year": 2015,
"PostCode": "SL6 9UD",
"Location": [
{
"type": "Point",
"coordinates": [
51.558455,
db.homeSales.aggregate([
{
$sort: {amount: -1}
},
{
$group:
{
_id: {$year: "$date"},
priciestPostCode: {$first: "$address.postcode"}
}
> 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",
{
"Year": 2015,
"PostCode": "SL6 9UD",
"Location": [
{
"type": "Point",
"coordinates": [
51.558455,
-0.756023
]
db.homeSales.aggregate([
{
$sort: {amount: -1}
},
{
$group:
{
_id: {$year: "$date"},
priciestPostCode: {$first: "$address.postcode"}
}
{
"Year": 2012,
"hightToLowPriceGap": 2923000
},
{
"Year": 2013,
"hightToLowPriceGap": 5092250
},
{
"Year": 2014,
db.annualHomePrices.aggregate([
{$project:
{
Year: "$year",
hightToLowPriceGap: {
$subtract: ["$highestPrice", "$lowestPrice"]
},
_id: 0
}
}
> db.annualHomePrices.findOne()
{
"_id": ObjectId("560957ac29a5574d557d426d"),
"highestPrice": 1000000,
"lowestPrice": 12000,
"averagePrice": 114059,
"priceStdDev": 81540,
"year": 1995
}
db.homeSales.aggregate([
{
$group:
{
_id: {$year: "$date"},
highestPrice: {$max: "$amount"},
lowestPrice: {$min: "$amount"},
averagePrice: {$avg: "$amount"},
priceStdDev: {$stdDevPop: "$amount"}
}