Reactivemongo getAsTry is not a member of PasswordInfo

89 views Asked by At

I'm working on a project to integrate play silhouette with reactivemongo

When I compile my project shows me an error like this:

[error] /reactivemongo-silhouette-rest/app/models/daos/PasswordInfoDAO.scala:83: value getAsTry is not a member of com.mohiva.play.silhouette.api.util.PasswordInfo [error] Future(Some(fullDoc.getAsTryBSONString.get))

mi method is this:

  def find(loginInfo: LoginInfo) = {

    implicit val userFormat = Macros.handler[PasswordInfo]
    val collection = db[BSONCollection]("PasswordInfo")

    val query = BSONDocument(
      "loginInfo" -> BSONDocument(
        "loginInfo" -> loginInfo.providerID,
        "loginInfo" -> loginInfo.providerKey
      )
    )

    val passwordInfo: Future[Option[PasswordInfo]] = collection.find( query ).one[PasswordInfo]

    passwordInfo.flatMap {
      case None =>
        Future.successful(Option.empty[PasswordInfo])
      case Some(fullDoc) =>
        Future(Some(fullDoc.getAsTry[PasswordInfo]("authInfo").get))
    }

    //Future.successful(data.get(loginInfo))

  }

The complete versiĆ³n is here:

https://github.com/hectorgool/reactivemongo-silhouette-rest/blob/master/app/models/daos/PasswordInfoDAO.scala

And the PasswordInfo is here:

https://github.com/mohiva/play-silhouette/blob/master/silhouette/app/com/mohiva/play/silhouette/api/util/PasswordHasher.scala

Can someone tell me what am doing wrong or what am i missing?

The repository on github is this: https://github.com/hectorgool/reactivemongo-silhouette-rest

1

There are 1 answers

1
Barry On

So by the time you get to your pattern match on passwordInfo its no longer a BSONDocument because of the call to one. You have in scope your userFormat for the type PasswordInfo which provides the implicit reader to the method one and which returns the Future[Option[PasswordInfo]] to your val passwordInfo.

This is why your error appears:

[error] /reactivemongo-silhouette-rest/app/models/daos/PasswordInfoDAO.scala:83: value getAsTry is not a member of com.mohiva.play.silhouette.api.util.PasswordInfo [error]

Because you already have your type [PasswordInfo] and its not a ReactiveMongo type like BSONDocument which has getAsTry defined.

I can't fully determine your return type but hopefully this helps.

Link to ReactiveMongo One method

Link to ReactiveMongo BSONDocument which has getAsTry