Adjust pis query to check last element

Signed-off-by: Fred Boniface <fred@fjla.uk>
This commit is contained in:
Fred Boniface 2023-04-24 12:57:40 +01:00
parent 1c944e9ae1
commit 3017981090
1 changed files with 13 additions and 13 deletions

View File

@ -9,19 +9,19 @@ async function findPisByOrigDest(start,end) {
const firstCrs = clean.cleanApiEndpointTxt(start.toLowerCase())
const lastCrs = clean.cleanApiEndpointTxt(end.toLowerCase())
const query = {
stops: {
$all: [
{ $elemMatch: { $eq: firstCrs } },
{ $elemMatch: { $eq: lastCrs } }
]
},
$expr: {
$eq: [
{ $arrayElemAt: [ "$stops", 0 ] },
firstCrs
]
}
}
stops: {
$all: [
{ $elemMatch: { $eq: firstCrs } },
{ $elemMatch: { $eq: lastCrs } }
]
},
$expr: {
$and: [
{ $eq: [{ $arrayElemAt: [ "$stops", -1 ] }, lastCrs] },
{ $eq: [{ $arrayElemAt: [ "$stops", 0 ] }, firstCrs] }
]
}
}
//const oldQuery = {$and:[{$expr:{$eq:[{$first:"$stops"},firstCrs]}},{$expr:{$eq:[{$last:"$stops"},lastCrs]}}]}
const search = db.query("pis", query)
return search