gpt4 book ai didi

scala - 升级到 ReactiveMongo 0.12.RC3 时类型不匹配

转载 作者:行者123 更新时间:2023-12-04 06:35:57 25 4
gpt4 key购买 nike

我目前正在升级到 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()))
}

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

Type mismatch, expected: (JSONCollection) => Future[NotInferedS], actual: (JSONCollection) => Any

最佳答案

我认为您缺少一些编译器消息,并且应该看到类似以下内容:

  (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]]()))

关于scala - 升级到 ReactiveMongo 0.12.RC3 时类型不匹配,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39376864/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com