-
Type: Bug
-
Resolution: Fixed
-
Priority: Major - P3
-
Affects Version/s: 4.1.0
-
Component/s: Scala
-
None
-
Environment:```
docker run --rm -p 27017:27017 mongo:4.4.2
docker run --rm -p 27017:27017 nikore/mongo:4.0-v2
```
```
openjdk version "1.8.0_265"
OpenJDK Runtime Environment (AdoptOpenJDK)(build 1.8.0_265-b01)
OpenJDK 64-Bit Server VM (AdoptOpenJDK)(build 25.265-b01, mixed mode)
```
```
Darwin MBP15-9814af 18.7.0 Darwin Kernel Version 18.7.0: Tue Nov 10 00:07:31 PST 2020; root:xnu-4903.278.51~1/RELEASE_X86_64 x86_64
```
```
scalaVersion 2.12.12
sbt 1.4.5
```
``` docker run --rm -p 27017:27017 mongo:4.4.2 docker run --rm -p 27017:27017 nikore/mongo:4.0-v2 ``` ``` openjdk version "1.8.0_265" OpenJDK Runtime Environment (AdoptOpenJDK)(build 1.8.0_265-b01) OpenJDK 64-Bit Server VM (AdoptOpenJDK)(build 25.265-b01, mixed mode) ``` ``` Darwin MBP15-9814af 18.7.0 Darwin Kernel Version 18.7.0: Tue Nov 10 00:07:31 PST 2020; root:xnu-4903.278.51~1/RELEASE_X86_64 x86_64 ``` ``` scalaVersion 2.12.12 sbt 1.4.5 ```
Driver fails to read `BsonInt64` as Long and results in ClassCastException:
Minimal reproducible example:
https://gist.github.com/aaabramov/89625595893d0ff513d1512b43a21caa
What happens here is that driver reads `field` as an `Integer` and puts it into `org.bson.Document#documentAsMap` then tries to class it as a `Long` in `org.bson.Document#getLong`.
And the interesting thing is we'll try to persist `coll.insertOne(Document("field" -> BsonInt64(Long.MaxValue))).toFuture()` everything would work just fine. So seems that driver chooses resulting type based on its value?
It was working fine with driver `"org.mongodb.scala" %% "mongo-scala-driver" % "2.7.0"`