reativemongo-play模块官网的例子, 为什么其中一个匿名函数不执行


clipboard.png


 coll.insert(shareJob).map { lastError =>
    Logger.debug(s"Successfully inserted with LastError: $lastError")
    Created
 }

map 里面的函数始终不执行,注释掉 Future.successful(Ok)就会抛出异常,有什么办法让他执行吗.这个例子完全照抄官网的,官网链接 http://reactivemongo.org/releases/0.11/documentation/tutorial/play2.html

code samples 的第三个例子

scala play reativemongo

从来不起名 9 years ago

应该是insert时发生异常了,处理一下异常:


 coll.insert(shareJob).map { lastError =>
    Logger.debug(s"Successfully inserted with LastError: $lastError")
    Created
 }.recover{
    case t =>
        Ok(e.getMessage)
}

耶稣yesue answered 9 years ago

Your Answer