【问题标题】:Working with ReactiveMongo (for play framework apps) in 20202020 年使用 ReactiveMongo(用于播放框架应用程序)
【发布时间】:2020-11-12 13:10:41
【问题描述】:

我已经建立了 playframework 2.8 的新项目,我的困境是:

1.我应该使用哪个依赖:

"org.reactivemongo" %% "reactivemongo" % "1.0"

  "org.reactivemongo" %% "play2-reactivemongo" // dont even think that there is 1.0 for play 2.8, is it deprecated?

2. 到目前为止,我使用 play-json 来序列化/反序列化我插入或从 mongo 获取的对象,例如:

object MongoSerializer {
  implicit val InstantFormat = CommonSerializers.InstantSerializers.BSONFormat
  implicit val MetadataFormat: OFormat[Metadata] = Json.format[Metadata]
  implicit val PairingFormat: OFormat[Pairing] = Json.format[Pairing]
  implicit val pairTypeFormat: Format[PairType] = EnumFormats.formats(PairType)
}

在我的 dbconfig 中我使用了 _.collection[JSONCollection],但我记得有人写道 JSONCollection 即将被弃用,并且将仅支持 BSONCollection 所以我想使用 BSONCollection

如您所见,我有点困惑,如果有人可以帮助我了解我应该使用什么设置以及哪种序列化/反序列化最适合它,我将不胜感激。谢谢!

【问题讨论】:

  • 请先阅读documentation
  • @cchantep 你说得对,我确实在文档上投入了更多时间,发现它很有帮助。我现在已经准备好使用版本"1.0.0-play28"。谢谢。

标签: mongodb scala reactivemongo play-reactivemongo


【解决方案1】:

我会选择第一个选项,因为我的一些结果是不同集合的聚合/自定义。因此,我将不得不自己编写自定义 BSON/JSON 转换器。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-06-12
    • 2015-12-17
    • 2014-10-16
    • 1970-01-01
    • 1970-01-01
    • 2012-05-09
    • 2014-07-16
    • 2019-03-23
    相关资源
    最近更新 更多