Order by distance when GPS coords are provided
MODIFY
src/storage/mongodb/ChargingStationStorage.ts
src/storage/mongodb/ChargingStationStorage.ts
@@ -269,6 +269,10 @@ export default class ChargingStationStorage {
if (!dbParams.sort) {
dbParams.sort = { _id: 1 };
}
+ // Position coordinates
+ if (Utils.containsGPSCoordinates(params.locCoordinates)) {
+ dbParams.sort = { distanceMeters: 1 };
+ }
aggregation.push({
$sort: dbParams.sort
});

MODIFY
src/storage/mongodb/CompanyStorage.ts
src/storage/mongodb/CompanyStorage.ts
@@ -186,6 +186,10 @@ export default class CompanyStorage {
if (!dbParams.sort) {
dbParams.sort = { name: 1 };
}
+ // Position coordinates
+ if (Utils.containsGPSCoordinates(params.locCoordinates)) {
+ dbParams.sort = { distanceMeters: 1 };
+ }
aggregation.push({
$sort: dbParams.sort
});

MODIFY
src/storage/mongodb/SiteAreaStorage.ts
src/storage/mongodb/SiteAreaStorage.ts
@@ -237,6 +237,10 @@ export default class SiteAreaStorage {
if (!dbParams.sort) {
dbParams.sort = { name: 1 };
}
+ // Position coordinates
+ if (Utils.containsGPSCoordinates(params.locCoordinates)) {
+ dbParams.sort = { distanceMeters: 1 };
+ }
aggregation.push({
$sort: dbParams.sort
});

MODIFY
src/storage/mongodb/SiteStorage.ts
src/storage/mongodb/SiteStorage.ts
@@ -400,6 +400,10 @@ export default class SiteStorage {
if (!dbParams.sort) {
dbParams.sort = { name: 1 };
}
+ // Position coordinates
+ if (Utils.containsGPSCoordinates(params.locCoordinates)) {
+ dbParams.sort = { distanceMeters: 1 };
+ }
aggregation.push({
$sort: dbParams.sort
});

Order by distance when GPS coords are provided