Adjust PIS query

Signed-off-by: Fred Boniface <fred@fjla.uk>
This commit is contained in:
Fred Boniface 2023-04-24 01:05:24 +01:00
parent 0596bd48e6
commit b66254213e

View File

@ -8,7 +8,9 @@ async function findPisByOrigDest(start,end) {
log.out(`pisServices.findPisByOrigDest: Searching for PIS for Orig: ${start}, Dest: ${end}`, "dbug") log.out(`pisServices.findPisByOrigDest: Searching for PIS for Orig: ${start}, Dest: ${end}`, "dbug")
const firstCrs = clean.cleanApiEndpointTxt(start.toLowerCase()) const firstCrs = clean.cleanApiEndpointTxt(start.toLowerCase())
const lastCrs = clean.cleanApiEndpointTxt(end.toLowerCase()) const lastCrs = clean.cleanApiEndpointTxt(end.toLowerCase())
const search = db.query("pis", {$and:[{$expr:{$eq:[{$first:"$stops"},firstCrs]}},{$expr:{$eq:[{$last:"$stops"},lastCrs]}}]}) const query = {stops: {$elemMatch: {$eq: firstCrs, $position: 0}}, stops: {$elemMatch: {$eq: lastCrs, $position: {$exists: false}}}}
const oldQuery = {$and:[{$expr:{$eq:[{$first:"$stops"},firstCrs]}},{$expr:{$eq:[{$last:"$stops"},lastCrs]}}]}
const search = db.query("pis", query)
return search return search
} }