Search code examples
mongodbscalamongo-scala-driver

Mongo scala driver: Float value can't be added


I am experiecing strange problem with scala mongo driver. When I execute the following part:

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
)

It gives me the following error:

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

But when I do the following:

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
)

It works. However my p._2 is Float.

enter image description here

So what is the problem here?

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

UPDATE:

I changed p._2 type from Float to Double and it is worked. Still it is strange.


Solution

  • Changed p._2 type from Float to Double and it is worked. Still it is strange.