Force sort of Connector IDs in Charging Station list
MODIFY
src/storage/mongodb/ChargingStationStorage.ts
src/storage/mongodb/ChargingStationStorage.ts
@@ -303,8 +303,11 @@ export default class ChargingStationStorage {
if (!dbParams.sort) {
dbParams.sort = { _id: 1 };
}
+ // Always add Conneector ID
+ dbParams.sort = { ...dbParams.sort, 'connectors.connectorId': 1 };
// Position coordinates
if (Utils.containsGPSCoordinates(params.locCoordinates)) {
+ // Override (can have only one sort)
dbParams.sort = { distanceMeters: 1 };
}
aggregation.push({

MODIFY
src/storage/mongodb/DatabaseUtils.ts
src/storage/mongodb/DatabaseUtils.ts
@@ -131,6 +131,12 @@ export default class DatabaseUtils {
if (!Utils.isEmptyArray(additionalParams.pipeline)) {
lookupParams.aggregation.push(...additionalParams.pipeline);
}
+ // Sort (for unwinded array props)
+ if (additionalParams.sort) {
+ lookupParams.aggregation.push({
+ $sort: additionalParams.sort
+ });
+ }
// Group back to arrays
lookupParams.aggregation.push(
JSON.parse(`{
@@ -163,7 +169,7 @@ export default class DatabaseUtils {
}`));
// Replace root
lookupParams.aggregation.push({ $replaceRoot: { newRoot: '$root' } });
- // Sort?
+ // Sort again (after grouping, sort is lost)
if (additionalParams.sort) {
lookupParams.aggregation.push({
$sort: additionalParams.sort

Force sort of Connector IDs in Charging Station list