我是 Scala 的新手,我想问一个简单的问题。
我有一个返回的函数Future[Option[T]
def findOne(query: JsObject)(implicit reader: Reads[T]): Future[Option[T]] = {
Logger.debug(s"Finding one: [collection=$collectionName, query=$query]")
collection.find(query).one[T]
}
我必须返回Future[Option[PasswordInfo]]
。
我试过了:
def find(loginInfo: LoginInfo): Future[Option[PasswordInfo]] = {
val result = find(Json.obj("loginInfo.providerID" -> loginInfo.providerID, "loginInfo.providerKey" -> loginInfo.providerKey))
result.onSuccess{
case something => Future.successful(Some(something).getOrElse(None))
}
}
我的课:
case class PersistentPasswordInfo(
loginInfo: LoginInfo,
authInfo: PasswordInfo
) extends TemporalModel {
override var created: Option[DateTime] = _
override var updated: Option[DateTime] = _
override var _id: Option[BSONObjectID] = _
}