diff --git a/src/main/scala/RelayCrowd.scala b/src/main/scala/RelayCrowd.scala index ef387160..0f77b1c5 100644 --- a/src/main/scala/RelayCrowd.scala +++ b/src/main/scala/RelayCrowd.scala @@ -36,8 +36,23 @@ final private class RelayCrowd(roomCrowd: RoomCrowd, mongo: Mongo)(using ex: Exe "pipeline" -> List( BSONDocument( "$match" -> BSONDocument( - "finished" -> false, - "$expr" -> BSONDocument("$eq" -> BSONArray("$tourId", "$$tourId")) + "$expr" -> BSONDocument( + "$and" -> + BSONArray( + BSONDocument( + BSONDocument("$eq" -> BSONArray("$tourId", "$$tourId")), + "$or" -> BSONArray( + BSONDocument("$exists" -> BSONArray("$finishedAt", false)), + BSONDocument( + "$gt" -> BSONArray( + "$finishedAt", + BSONDateTime(nowMillis - 1000 * 60 * 60 * 2) // 2 hours + ) + ) + ) + ) + ) + ) ) ), BSONDocument("$sort" -> BSONDocument("createdAt" -> 1)),