scalareactivemongoplay-reactivemongo

Method find in ReactiveMongo is deprecated. Use 'find' with optional projection


I am working on a project which integrates play framework with reactive mongo. I recently upgraded reactive mongo to 0.18.5 version. After upgrading i get the warning:

method find in trait GenericCollection is deprecated (since 0.16.0): Use find with optional `projection`

Although the code compiles and works just fine with this warning but i would like to know how to eliminate this warning completely.

I tried adding projection field to the find method as :

 .find(
       Json.obj(
         "cid" -> cid,
         "out"-> out,
         "isDone" -> false,
         "numberOfAttempts" -> Json.obj("$lte" -> 3),
         "isActive" -> true
       ),projection=Option.empty

But this gives the following error:

 both object BSONDocumentWrites in trait ImplicitBSONHandlers of type reactivemongo.play.json.package.BSONDocumentWrites.type and object JsObjectDocumentWriter in trait ImplicitBSONHandlers of type and  reactivemongo.play.json.package.JsObjectDocumentWriter.type
 match expected type play.api.libs.json.OWrites[J]

Here are the version of libraries i am using:

scalaVersion := "2.12.8"

libraryDependencies += "org.reactivemongo" %% "play2-reactivemongo" % "0.18.5-play27"

Can anyone guide me as to how to remove this warning and properly work with projections. I know that projection is used to return a specific field from the query result but in my case i am trying to return an entire object. Appreciate the help.


Solution

  • Use Option.empty[JsObject] to remove type ambiguity for the projection (or use silencer to ignore this warning).