make the DB $all selector more type safe
parent
e3f8200a98
commit
3d1ac40eb6
|
@ -336,7 +336,7 @@ trait dsl {
|
|||
}
|
||||
|
||||
trait ArrayOperators { self: ElementBuilder =>
|
||||
def $all[T](values: T*)(implicit writer: BSONWriter[T, _ <: BSONValue]): SimpleExpression[BSONDocument] = {
|
||||
def $all[T](values: Seq[T])(implicit writer: BSONWriter[T, _ <: BSONValue]): SimpleExpression[BSONDocument] = {
|
||||
SimpleExpression(field, $doc("$all" -> values))
|
||||
}
|
||||
|
||||
|
|
|
@ -71,7 +71,7 @@ final class CrosstableApi(
|
|||
UserRepo.orderByGameCount(x1, x2) map (_ -> List(x1, x2).sorted) flatMap {
|
||||
case (Some((u1, u2)), List(su1, su2)) =>
|
||||
val selector = $doc(
|
||||
Game.BSONFields.playerUids.$all(u1, u2),
|
||||
Game.BSONFields.playerUids $all List(u1, u2),
|
||||
Game.BSONFields.status $gte chess.Status.Mate.id)
|
||||
|
||||
import reactivemongo.api.collections.bson.BSONBatchCommands.AggregationFramework.{ Match, SumValue, GroupField }
|
||||
|
|
|
@ -387,7 +387,7 @@ object GameRepo {
|
|||
|
||||
def lastGameBetween(u1: String, u2: String, since: DateTime): Fu[Option[Game]] =
|
||||
coll.uno[Game]($doc(
|
||||
F.playerUids.$all(u1, u2),
|
||||
F.playerUids $all List(u1, u2),
|
||||
F.createdAt $gt since
|
||||
))
|
||||
|
||||
|
|
|
@ -70,7 +70,7 @@ object Query {
|
|||
)
|
||||
|
||||
def opponents(u1: User, u2: User) =
|
||||
$doc(F.playerUids.$all(List(u1, u2).sortBy(_.count.game).map(_.id):_*))
|
||||
$doc(F.playerUids $all List(u1, u2).sortBy(_.count.game).map(_.id))
|
||||
|
||||
val noProvisional: Bdoc = $doc(
|
||||
"p0.p" $exists false,
|
||||
|
|
|
@ -95,7 +95,7 @@ private[video] final class VideoApi(
|
|||
else Paginator(
|
||||
adapter = new Adapter[Video](
|
||||
collection = videoColl,
|
||||
selector = $doc("tags".$all(tags: _*)),
|
||||
selector = $doc("tags" $all tags),
|
||||
projection = $empty,
|
||||
sort = $doc("metadata.likes" -> -1)
|
||||
) mapFutureList videoViews(user),
|
||||
|
@ -176,7 +176,7 @@ private[video] final class VideoApi(
|
|||
tags.filterNot(_.isNumeric)
|
||||
}
|
||||
else videoColl.aggregate(
|
||||
Match($doc("tags".$all(filterTags: _*))),
|
||||
Match($doc("tags" $all filterTags)),
|
||||
List(Project($doc("tags" -> true)),
|
||||
Unwind("tags"), GroupField("tags")("nb" -> SumValue(1)))).map(
|
||||
_.documents.flatMap(_.asOpt[TagNb]))
|
||||
|
|
Loading…
Reference in New Issue