use $lookup.pipeline for the relay pager

pull/9734/head
Thibault Duplessis 2021-09-05 17:32:13 +02:00
parent 958fe7ba11
commit b6635283ae
1 changed files with 15 additions and 23 deletions

View File

@ -25,29 +25,21 @@ final class RelayPager(tourRepo: RelayTourRepo, roundRepo: RelayRoundRepo)(impli
Match(tourRepo.selectors.official ++ tourRepo.selectors.inactive) -> List(
Sort(Descending("syncedAt")),
PipelineOperator(
$doc(
"$lookup" -> $doc(
"from" -> roundRepo.coll.name,
"as" -> "round",
"let" -> $doc("id" -> "$_id"),
"pipeline" -> $arr(
$doc(
"$match" -> $doc(
"$expr" -> $doc(
$doc("$eq" -> $arr("$tourId", "$$id"))
)
)
),
$doc(
"$sort" -> $doc(
"startedAt" -> -1,
"startsAt" -> -1,
"name" -> -1
)
),
$doc("$limit" -> 1),
$doc("$addFields" -> $doc("sync.log" -> $arr()))
)
$lookup.pipeline(
from = roundRepo.coll,
as = "round",
local = "_id",
foreign = "tourId",
pipeline = List(
$doc(
"$sort" -> $doc(
"startedAt" -> -1,
"startsAt" -> -1,
"name" -> -1
)
),
$doc("$limit" -> 1),
$doc("$addFields" -> $doc("sync.log" -> $arr()))
)
)
),