Skip to content

Instantly share code, notes, and snippets.

@danared
Created November 3, 2015 16:22
Show Gist options
  • Save danared/7907e8667b5d339aecf3 to your computer and use it in GitHub Desktop.
Save danared/7907e8667b5d339aecf3 to your computer and use it in GitHub Desktop.
var findNeighbours = function (spot, yearTag) {
var result = db.postcodes.aggregate([
{
$geoNear:
{
near: spot,
distanceField: "distance",
num: 5,
spherical: true
}
},
{
$group: {
_id: yearTag,
"neighbours": {
$addToSet: "$postcode"
}
}
}
]);
return result.result;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment