From 5da7a951e320b0d9126e2ae4176392756c59ddab Mon Sep 17 00:00:00 2001 From: Fred Boniface Date: Fri, 21 Apr 2023 21:12:49 +0100 Subject: [PATCH] Add search query for findPisByOrigDest Signed-off-by: Fred Boniface --- src/services/pis.services.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/services/pis.services.js b/src/services/pis.services.js index 4df4595..54cea13 100644 --- a/src/services/pis.services.js +++ b/src/services/pis.services.js @@ -7,7 +7,11 @@ async function findPisByOrigDest(start,end) { log.out(`pisServices.findPisByOrigDest: Searching for PIS for Orig: ${start}, Dest: ${end}`, "dbug") /* Here, I need to query the collection for a document with a stops array starting with $start and ending with $end. This will return an array of one or more pis codes and stopping patterns*/ - const search = db.query("pis", {query:query}) + // Query to find first stop: {$expr:{$eq:[{$first:"$stops"},start]}} + // Query to find end stop: {$expr:{$eq:[{$last:"$stops"},end]}} + // Attempt at combining the queries: + // {$and:[{$expr:{$eq:[{$first:"$stops"},start]}},{$expr:{$eq:[{$last:"$stops"},end]}}]} + const search = db.query("pis", {$and:[{$expr:{$eq:[{$first:"$stops"},start]}},{$expr:{$eq:[{$last:"$stops"},end]}}]}) return search }