我有三个对象
case class Metric(val name: String, val tags: Map[String, String])
case class Threshold(val metric: Metric, val critical: Long, val warning: Long)
class Profile(val name: String, val thresholds: List[Threshold])
我打算只将 Profile 对象存储在 Mongo DB 中,但在 Scala 应用程序中,它们应该由它们的类型表示。
我正在使用相同的子集,并定义了以下性质
implicit val reader = ValueReader[Threshold]({
case metric(metric) ~ critical(critical) ~ warning(warning) =>
new Threshold(metric, critical, warning)
})
implicit val writer = {
def f(threshold: Threshold): DBObject =
(metric -> threshold.metric) ~ (critical -> threshold.critical) ~ (warning -> threshold.warning)
ValueWriter(f _)
}
我如何查询往返 Mongo Now?有这方面的例子吗?