【发布时间】:2014-11-19 00:21:13
【问题描述】:
我正在用 Scala 编写一个 play 2.3 应用程序。 我使用 mongoDB 数据库和 ReactiveMongo 驱动程序。 我调用来读取/写入/更新数据库中的日期的方法返回一个 Future[Option[T]]。 我的问题是:如果我有一种方法可以先更新文档,然后在阅读更新后的文档后,我是否需要 onComplete 语句? 例如:
def updatePasswordInfo(user: LoginUser,info: PasswordInfo): scala.concurrent.Future[Option[BasicProfile]] = {
import LoginUser.passwordInfoFormat //import the formatter
//the document query
val query = Json.obj("providerId" -> user.providerId,
"userId" -> user.userId
)
val newPassword = Json.obj("passswordInfo" -> info)// the new password
//search if the user exists and
val future = UserServiceLogin.update(query, newPassword) //update the document
for {
user <- UserServiceLogin.find(query).one
} yield user //return the new LoginUser
}
在使用UserServicelogin.find(query).one 语句之前我需要使用 onComplete 语句是否正确?
【问题讨论】:
标签: mongodb scala playframework-2.0 future reactivemongo