【问题标题】:Method find in ReactiveMongo is deprecated. 0.20.3不推荐使用 ReactiveMongo 中的方法 find 。 0.20.3
【发布时间】:2020-03-18 16:42:47
【问题描述】:

我正在将响应式 mongo "0.17.1-play26" 升级到 "0.20.3" 但是,它给出了很多错误。我正在访问 MongoDB 以查找数据。它给了我上述错误。请帮忙

这是我给出的声明

stdntcollection.find(query,Option(select)).cursor[studentDetails]().collect[List(-1,Cursor.FailOnError[List[studentDetails]]())` 

studentdetails 是一个案例类。结构类似

     case class studentDetails(
         roll: Option[String], 
         subjct: String    
     )

     object studentDetails {
         implicit val studentDetailsReads: Reads[studentDetails] = (
             (__ \ "roll").readNullable[String] and
             (__ \ "subjct").read[String])(studentDetails.apply _)

         implicit val studentDetailsWrites: Writes[studentDetails] = (
             (__ \ "roll").writeNullable[String] and
             (__ \ "subjct").write[String](unlift(studentDetails.unapply))
     }

这是错误:

方法 find 的参数不足:(隐式编写器:stdntcollection.pack.Writer[play.api.libs.json.JsObject],隐式编写器:stdntcollection.pack.Writer[scala.collection.Map[String,Int] ])reactivemongo.api.collections.GenericQueryBuilder[stdntcollection.pack.type]。未指定值参数 swriter, pwriter。

【问题讨论】:

  • 请正确格式化您的问题
  • 这是我的第一篇文章,我想更清楚

标签: scala reactivemongo


【解决方案1】:

我猜您正在使用带有 JSON 的集合,并且您作为投影第二个参数传递的 select 缺少隐含。如documentation所示:

import reactivemongo.play.json._

注意 #1:studentDetails 不尊重案例类的 Recommended naming

注意 #2:JSONCollection 可能会从 1.0 版中删除,新的转换支持更简单的 JSON。

【讨论】:

  • 包 json 中的包对象 json 已弃用(自 0.19.2 起):将被从 reactivemongo-play-json-compat 替换为 reactivemongo.play.json.compat._
  • 导入 play.modules.reactivemongo._
  • 导入 reactivemongo.play.json._
  • 导入 reactivemongo.play.json.collection._
  • 导入 play.api.libs.json._
猜你喜欢
  • 2018-08-26
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-05-05
  • 1970-01-01
  • 2019-10-13
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多