Permalink
Browse files

[reactivemongo] $in extractor

  • Loading branch information...
cchantep
cchantep committed Sep 26, 2014
1 parent d213d6d commit f5e58c0dbf83e3f067af8081a39575550657115a
View
@@ -268,9 +268,13 @@ val queryHandler = QueryHandler { queryRequest =>
// Matching on count query
resultK
case CountRequest(_, ("property", InClause(
BSONString("A") :: BSONString("B") :: Nil)) :: Nil) =>
resultL // matches count with selector on 'property' using $in operator
case Request("col1", SimpleBody(("$in", ValueList(bsonA, bsonB)) :: Nil)) =>
// Matching BSONArray using with $in operator
resultL
resultM
}
}
```
@@ -116,6 +116,13 @@ object SimpleBody {
}
/** Complete request body extractor; Matches body with many documents. */
object RequestBody {
/** @return List of document, each document as list of its BSON properties. */
def unapply(body: List[BDoc]): Option[List[List[(String, BSONValue)]]] =
Some(body.map(_.underlying.elements.toList))
}
/**
* Extractor of properties for a document used a BSON value
* (when operator is used, e.g. `{ 'age': { '\$gt': 10 } }`).
@@ -154,6 +161,23 @@ object CountRequest {
}
}
/**
* In clause extractor
* (\$in with BSONArray; e.g. { '\$in': [ ... ] })
*/
object InClause {
/**
* Matches BSON property with name \$in and a BSONArray as value,
* and extracts subvalues from the array.
*/
def unapply(bson: BSONValue): Option[List[BSONValue]] =
bson match {
case ValueDocument(("$in", a @ BSONArray(_)) :: _)
Some(a.values.toList)
case _ None
}
}
/**
* Meta-extractor, to combine extractor on BSON properties.
* @see SimpleBody
@@ -329,6 +329,14 @@ object RequestSpec extends org.specs2.mutable.Specification
BSONDouble(c) :: Nil) ok
}
}
"be extracted from an $in clause" in {
BSONDocument("selector" -> BSONDocument("$in" -> BSONArray("A", "B"))).
aka("body") must beLike {
case ValueDocument(("selector", InClause(
BSONString("A") :: BSONString("B") :: Nil)) :: Nil) ok
}
}
}
}

0 comments on commit f5e58c0

Please sign in to comment.