How do I read a primitive type from database with ReactiveMongo?

32 Views Asked by At

The following piece of code:

  def getInitState(): Future[String] = states.flatMap {
    _.find(
      selector   = Json.obj("init" -> true),
      projection = Some(Json.obj("name" -> 1))
    ).requireOne[String]
  }

causes a compilation error: could not find implicit value for parameter reader: reactivemongo.api.bson.BSONDocumentReader[String] pointing to the [String] type parameter of requireOne. It probably should be noted that I'm using ReactiveMongo Play module and reactivemongo-play-json-compat, both of version 1.1.0-play28-RC11. First question is, can ReactiveMongo return primitive types from queries? If so, how do I do that?

Using Play Json objects as parameters in find also produces warnings like value jsObjectWrites in trait LowPriorityPackageCompat is deprecated. The value in question looks like this:

private[json] trait LowPriorityPackageCompat {

  @deprecated("Will be removed when provided by Play-JSON itself", "0.20.6")
  implicit final val jsObjectWrites: OWrites[JsObject] =
    OWrites[JsObject](identity)
}

and I'm not using it directly, so I think this is something ReactiveMongo developers should worry about. Second question is am I right? If not, please explain how to fix it.

Also, I've been really frustrated with quality of the official ReactiveMongo doc. Third question is, is there any better doc?

0

There are 0 best solutions below