【问题标题】:Type mismatch when upgrading to ReactiveMongo 0.12.RC3升级到 ReactiveMongo 0.12.RC3 时类型不匹配
【发布时间】:2023-03-22 11:34:02
【问题描述】:

我目前正在升级到 0.12.RC3,希望能修复我遇到的 following issue。升级后,我收到了collect 方法的弃用警告。

所以我从:

def find(query: JsObject = Json.obj())(implicit reader: Reads[T]): Future[List[T]] = {
    collection.flatMap(_.find(query).cursor[T](ReadPreference.nearest).collect[List]())
}

收件人:

def find(query: JsObject = Json.obj())(implicit reader: Reads[T]): Future[List[T]] = {
    collection.flatMap(_.find(query).cursor[T](ReadPreference.nearest).collect[List](Int.MaxValue, Cursor.FailOnError()))
}

但是,不幸的是,我收到以下错误:

类型不匹配,预期:(JSONCollection) => Future[NotInferedS], 实际:(JSONCollection) => 任何

【问题讨论】:

    标签: scala reactivemongo play-reactivemongo


    【解决方案1】:

    我认为您遗漏了一些编译器消息,应该会看到如下内容:

      (maxDocs: Int,stopOnError: Boolean)(implicit cbf: scala.collection.generic.CanBuildFrom[List[_],T,List[T]], implicit ec: scala.concurrent.ExecutionContext)scala.concurrent.Future[List[T]] <and>
      (maxDocs: Int,err: reactivemongo.api.Cursor.ErrorHandler[List[T]])(implicit cbf: scala.collection.generic.CanBuildFrom[List[_],T,List[T]], implicit ec: scala.concurrent.ExecutionContext)scala.concurrent.Future[List[T]]
     cannot be applied to (Int, reactivemongo.api.Cursor.ErrorHandler[Any])
    Error occurred in an application involving default arguments.
               collection.flatMap(_.find(query).cursor[T](ReadPreference.nearest).collect[List](Int.MaxValue, Cursor.FailOnError()))
    

    这意味着在这种情况下,如果您想使用新的collect 而不是已弃用的ErrorHandler(有FailOnError),结果类型为:FailOnError[List[T]]

    def find(query: JsObject = Json.obj())(implicit reader: Reads[T]): Future[List[T]] = collection.flatMap(_.find(query).cursor[T](ReadPreference.nearest).collect[List](Int.MaxValue, Cursor.FailOnError[List[T]]()))
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-06-25
      • 1970-01-01
      • 1970-01-01
      • 2012-07-10
      • 1970-01-01
      • 2021-03-21
      • 1970-01-01
      相关资源
      最近更新 更多