首页 文章

scala play reactivemongo java.util.NoSuchElementException:None.get

提问于
浏览
-1

当我尝试使用reactive mongo插件更新mongodb文件时,我会抛出异常 . 任何帮助表示赞赏 . 谢谢

DiagramDAO.updateDiagram(diagramId,initial.get).onComplete { 
    case Failure(e) =>  Logger.debug("Diagram failed to go to initial state    "+e.printStackTrace())  
    case Success(writeResult) => println(s"successfully updated document with     initial state: $writeResult")
    }

java.util.NoSuchElementException:无法在scala.None $ .get(Option.scala:347)scala.None $ .get(Option.scala:345)at play.api.libs.json.JsLookupResult $ class .get(jsLookup.scala:98)at play.api.libs.json.JsUndefined.get(JsLookup.scala:127)at play.modules.reactivemongo.json.collection.JSONBatchCommands $ LastErrorReader $$ anonfun $ read $ 7 $$ anonfun $ apply $ 30 $$ anonfun $ apply $ 31 $$ anonfun $ apply $ 33 $$ anonfun $ apply $ 34 $$ anonfun $ apply $ 35 $$ anonfun $ apply $ 39.apply(jsoncollection.scala:281)at play.modules.reactivemongo.json.collection.JSONBatchCommands $ $$ LastErrorReader $ anonfun读取$ $$ 7 $ anonfun申请$ 30 $$ anonfun $ $申请31 $$ anonfun $ $申请32 $$ anonfun $ $申请33 $$ anonfun $ $申请$ 34 $ anonfun $ apply $ 39.apply $申请$ 39.apply(jsoncollection.scala:277)at play.api.libs.json.JsResult $ class.flatMap(JsResult.scala:107)at play.api.libs.json . JsSuccess.flatMap(JsResult.scala:9)at play.modules.reactivemongo.json.collection.JSONBatchCommands $ LastErrorReader $$ anonfun $ read $ 7 $$ anonfun $ apply $ 30 $$ anonfun $申请$ 31 $$ anonfun $ apply $ 33 $$ anonfun $ apply $ 34 $$ anonfun $ apply $ 35.apply(jsoncollection.scala:277)at play.modules.reactivemongo.json.collection.JSONBatchCommands $ LastErrorReader $ $ $ anonfun读取$ $$ 7 $ anonfun申请$ 30 $$ anonfun $ $申请31 $$ anonfun $ $申请32 $$ anonfun $ $申请33 $$ anonfun $ $申请34 $$ anonfun $ $申请35.apply(jsoncollection.scala:276) at play.api.libs.json.JsResult $ class.flatMap(JsResult.scala:107)at play.api.libs.json.JsSuccess.flatMap(JsResult.scala:9)at play.modules.reactivemongo.json.collection .JSONBatchCommands $ LastErrorReader $$ anonfun $ read $ 7 $$ anonfun $ apply $ 30 $$ anonfun $ apply $ 32 $$ anonfun $ apply $ 33 $$ anonfun $ apply $ 34.apply(jsoncollection.scala:276)at play.modules.reactivemongo.json.collection.JSONBatchCommands $ $$ LastErrorReader $ anonfun读取$ $$ 7 $ anonfun申请$ 30 $$ anonfun $ $申请31 $$ anonfun $ $申请32 $$ anonfun $ $申请33 $$ anonfun $ $申请34在play.api.libs.json.Js的play.api.libs.json.JsResult $ class.flatMap(JsResult.scala:107)中申请(jsoncollection.scala:275)在play.modules.reactivemongo.json.collection.JSONBatchCommands上的Success.flatMap(JsResult.scala:9)$ LastErrorReader $$ anonfun $读取$ 7 $$ anonfun $ apply $ 30 $$ anonfun $ apply $ 31 $$ anonfun $ apply $ 32 $$ anonfun $ apply $ 33.apply(jsoncollection.scala:275)at play.modules.reactivemongo.json.collection.JSONBatchCommands $ LastErrorReader $$ anonfun $ read $ 7 $$ anonfun $ apply $ 30 $$ anonfun $ apply $ 31 $$ anonfun $ apply $ 32 $$ anonfun $ play.api.libs.json.JsResult $ class.flatMap(JsResult.scala:107)at play.api.libs.json.JsSuccess.flatMap $(申请$ 33.apply(jsoncollection.scala:274) JsResult.scala:9)at play.modules.reactivemongo.json.collection.JSONBatchCommands $ LastErrorReader $$ anonfun $ read $ 7 $$ anonfun $ apply $ 30 $$ anonfun $ apply $ 31 $$ anonfun $ apply $ 32.apply(jsoncollection.scala :274)at play.modules.reactivemongo.json.collection.JSONBatchCommands $ LastErrorReader $$ anonfun $ read $ 7 $$ anonfun $ apply $ 30 $$ anonfun $ apply $ 31 $$ anonfun $ apply $ 32.apply(jsoncollection.scala:273) at play.api.libs.json.JsResult $ class.flatMap(JsResult.scala:107)at play.ap i.libs.json.JsSuccess.flatMap(JsResult.scala:9)at play.modules.reactivemongo.json.collection.JSONBatchCommands $ LastErrorReader $$ anonfun $ read $ 7 $$ anonfun $ apply $ 30 $$ anonfun $ apply $ 31.apply (jsoncollection.scala:273)at play.modules.reactivemongo.json.collection.JSONBatchCommands $ LastErrorReader $$ anonfun $ read $ 7 $$ anonfun $ apply $ 30 $$ anonfun $ apply $ 31.apply(jsoncollection.scala:272)at play .api.libs.json.JsResult $ class.flatMap(JsResult.scala:107)at play.api.libs.json.JsSuccess.flatMap(JsResult.scala:9)at play.modules.reactivemongo.json.collection.JSONBatchCommands $ LastErrorReader $$ anonfun $读取$ 7 $$ anonfun $ apply $ 30.apply(jsoncollection.scala:272)at play.modules.reactivemongo.json.collection.JSONBatchCommands $ LastErrorReader $$ anonfun $读取$ 7 $$ anonfun $ apply $ 30 . play(jsoncollection.scala:271)at play.api.libs.json.JsResult $ class.flatMap(JsResult.scala:107)at play.api.libs.json.JsSuccess.flatMap(JsResult.scala:9)at play .modules.reactivemongo.json.collection.JSONBatchCommands $ LastErrorReader $$一nonfun $在play.modules.reactivemongo.json.collection.JSONBatchCommands中读取$ 7.apply(jsoncollection.scala:271)$ LastErrorReader $$ anonfun $在play.api.libs.json中读取$ 7.apply(jsoncollection.scala:270)在play.modules.reactivemongo.json.collection.JSONBatchCommands的play.api.libs.json.JsSuccess.flatMap(JsResult.scala:9)中的.JsResult $ class.flatMap(JsResult.scala:107)$ LastErrorReader $ .reads( jsoncollection.scala:270)at play.modules.reactivemongo.json.JSONSerializationPack $ .deserialize(json.scala:376)at play.modules.reactivemongo.json.JSONSerializationPack $ .deserialize(json.scala:350)at reactivemongo.api .SerializationPack $ class.readAndDeserialize(serializationpack.scala:24)at play.modules.reactivemongo.json.JSONSerializationPack $ .readAndDeserialize(json.scala:350)at atreactivemongo.api.SerializationPack $ class.readAndDeserialize(serializationpack.scala:32)at play.modules.reactivemongo.json.JSONSerializationPack $ .readAndDeserialize(json.scala:350)at reactivemongo.api.collections.GenericCollection $$ anonfun $ update $ 1 $$ anonfun $ apply $ 14.apply(genericcollection.scala:297)at scate.util.Success的reactivemongo.api.aplections.GenericCollection $$ anonfun $ update $ 1 $$ anonfun $ apply $ 14.apply(genericcollection.scala:297) $$ anonfun $ map $ 1.apply(Try.scala:236)at scala.util . 在scala.concurrent的scala.util.Success.map(Try.scala:236)处尝试$ .apply(Try.scala:191) .Future $$ anonfun $ map $ 1.apply(Future.scala:235)at scala.concurrent.Future $$ anonfun $ map $ 1.apply(Future.scala:235)at scala.concurrent.impl.CallbackRunnable.run(Promise .scala:32)scala.concurrent.impl.ExecutionContextImpl $ AdaptedForkJoinTask.exec(ExecutionContextImpl.scala:121)at scala.concurrent.forkjoin.ForkJoinTask.doExec(ForkJoinTask.java:260)at scala.concurrent.forkjoin.ForkJoinPool $ WorkQueue.runTask(叉JoinPool.java:1339)scala.concurrent.forkjoin.ForkJoinPool.runWorker(ForkJoinPool.java:1979)scala.concurrent.forkjoin.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:107)[debug] - 应用程序 - 图表未能通过到初始状态()

2 回答

  • 0

    Option.get 是魔鬼,避免它..这是另一种方式

    initial foreach { ival =>
        DiagramDAO.updateDiagram(diagramId,ival).onComplete { 
            case Failure(e) =>  Logger.debug("Diagram failed to go to initial state    "+e.printStackTrace())  
            case Success(writeResult) => println(s"successfully updated document with     initial state: $writeResult")
        }
    }
    
  • 1

    正如您的堆栈所说,您正试图获得无 Value . 尽量避免在Option上使用'get'方法 . 对于您的情况,您可以使用'map':

    initial.map(valueOfInitial =>
      DiagramDAO.updateDiagram(diagramId, valueOfInitial).onComplete { 
        ...
      }
    )
    

相关问题