我正在Scala寫一個play 2.3應用程序。 我使用mongoDB數據庫和ReactiveMongo驅動程序。 我調用讀取/寫入/更新數據庫中日期的方法返回Future [Option [T]]。 我的問題是這樣的:如果我有一個方法,第一次更新文件,並在閱讀更新後的文件,我需要一個onComplete語句或不? 例如:瞭解未來[Option [T]] reactiveMongo
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
}
是正確的O I前需要使用的onComplete語句中使用UserServicelogin.find(query).one
聲明?
爲什麼這個工作?爲什麼第一條語句在第一條語句完成後執行? – 2014-09-24 13:42:46
@albertoadami,看我更新的答案 – 2014-09-24 13:45:59