I have a project set up with playframework 2.2.0
and play2-reactivemongo 0.10.0-SNAPSHOT
. I'd like to query for few documents by their ids, in a fashion similar to this:
def usersCollection = db.collection[JSONCollection]("users")
val ids: List[String] = /* fetched from somewhere else */
val query = ??
val users = usersCollection.find(query).cursor[User].collect[List]()
As a query I tried:
Json.obj("_id" -> Json.obj("$in" -> ids)) // 1
Json.obj("_id.$oid" -> Json.obj("$in" -> ids)) // 2
Json.obj("_id" -> Json.obj("$oid" -> Json.obj("$in" -> ids))) // 3
for which first and second return empty lists and the third fails with error assertion 10068 invalid operator: $oid
.
Json.obj("_id" -> Json.obj("$in" -> ids.map(BSONObjectID(_))))
? – FinnellWrite[BSONObjectID]
in implicit scope, andplay-reactivemongo
offers only partial one. Moreover, writing one feels not efficient, as you'll do conversionBSONValue
->JsValue
->BSONValue
in this case. – Botanize