From 6ca8de8c75499d136e3951db25ab60309bcbb16c Mon Sep 17 00:00:00 2001 From: Fred Boniface Date: Mon, 24 Apr 2023 01:33:15 +0100 Subject: [PATCH] Again, adjust PIS query Signed-off-by: Fred Boniface --- src/services/pis.services.js | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/src/services/pis.services.js b/src/services/pis.services.js index 58861ed..89fb87d 100644 --- a/src/services/pis.services.js +++ b/src/services/pis.services.js @@ -10,22 +10,20 @@ async function findPisByOrigDest(start,end) { const lastCrs = clean.cleanApiEndpointTxt(end.toLowerCase()) const query = { stops: { - $elemMatch: { - $eq: firstCrs, - $position: 0 - } - }, - stops: { - $elemMatch: { - $eq: lastCrs, - $position: { - $exists: false - } - } + $all: [ + { $elemMatch: { $eq: firstCrs } }, + { $elemMatch: { $eq: lastCrs } } + ] + }, + $expr: { + $eq: [ + { $arrayElemAt: [ "$stops", 0 ] }, + firstCrs + ] + } } - } const oldQuery = {$and:[{$expr:{$eq:[{$first:"$stops"},firstCrs]}},{$expr:{$eq:[{$last:"$stops"},lastCrs]}}]} - const search = db.query("pis", query) + const search = db.query("pis", oldQuery) return search }