Mongo scala驱动程序:无法添加浮动值

时间:2017-12-15 09:25:25

标签: mongodb scala mongo-scala-driver

我遇到scala mongo driver的奇怪问题。当我执行以下部分时:

val doc:org.mongodb.scala.Document = org.mongodb.scala.Document(
  "junctionId"  -> junctionId,
  "efficiencyArray" -> efficiencyMap.map(p=> org.mongodb.scala.Document(
    "minute" -> p._1,
    "efficiency" -> p._2,
    "debugStuff" -> net.liftweb.json.Serialization.write(p._3)
  )),
  "totalCarCount" -> totalCarCount
)

它给了我以下错误:

Error:(182, 22) type mismatch;
found   : (String, Float)
required: org.mongodb.scala.bson.BsonMagnets.CanBeBsonElement
    "efficiency" -> p._2,

但是当我做以下事情时:

val doc:org.mongodb.scala.Document = org.mongodb.scala.Document(
  "junctionId"  -> junctionId,
  "efficiencyArray" -> efficiencyMap.map(p=> org.mongodb.scala.Document(
    "minute" -> p._1,
    "efficiency" -> 2.555,
    "debugStuff" -> net.liftweb.json.Serialization.write(p._3)
  )),
  "totalCarCount" -> totalCarCount
)

有效。不过我的p._2Float

enter image description here

那么这里有什么问题?

Scala version: 2.11.8
mongo-scala-driver version: 2.1.0

更新

我将p._2类型从Float更改为Double,然后就可以了。还是很奇怪。

1 个答案:

答案 0 :(得分:0)

p._2类型从Float更改为Double,然后就可以了。还是很奇怪。