Add pipeline for finding station by distance

Signed-off-by: Fred Boniface <fred@fjla.uk>
This commit is contained in:
Fred Boniface 2024-06-30 20:46:37 +01:00
parent 6cfc42f22e
commit e1fc4b1db2

View File

@ -0,0 +1,42 @@
export function findStationsByDistancePipeline(count: number) {
return [
{
'$geoNear': {
'near': {
'type': 'Point',
'coordinates': [
-5.149929, 58.350661
]
},
'distanceField': 'distance'
}
}, {
'$limit': count
}, {
'$addFields': {
'miles': {
'$divide': [
{
'$round': {
'$multiply': [
{
'$divide': [
'$distance', 1609.34
]
}, 4
]
}
}, 4
]
}
}
}, {
'$project': {
'_id': 0,
'3ALPHA': 1,
'NLCDESC': 1,
'miles': 1
}
}
]
}