Details
-
Bug
-
Resolution: Done
-
Major - P3
-
3.3.0
-
None
-
MongoDB server 3.2.8
Windows 7 x64
java version "1.8.0_45"
Java(TM) SE Runtime Environment (build 1.8.0_45-b15)
Java HotSpot(TM) 64-Bit Server VM (build 25.45-b02, mixed mode)
Description
Using the async Java driver and running a `distinct` query over a string-typed field that may contain null values results in `org.bson.BsonInvalidOperationException` being thrown. Example code using the `distinct` query operation, sanitized and simplified:
mongoCollection
|
.distinct("stringFieldName", String.class)
|
.into(new ArrayList<String>(), asyncCallback)
|
A workaround is available to filter out null values:
mongoCollection
|
.distinct("stringFieldName", Filters.ne("stringFieldName", new BsonNull()), String.class)
|
.into(new ArrayList<String>(), asyncCallback)
|
Exception:
org.bson.BsonInvalidOperationException: readString can only be called when CurrentBSONType is STRING, not when CurrentBSONType is NULL.
|
at org.bson.AbstractBsonReader.verifyBSONType(AbstractBsonReader.java:655)
|
at org.bson.AbstractBsonReader.checkPreconditions(AbstractBsonReader.java:687)
|
at org.bson.AbstractBsonReader.readString(AbstractBsonReader.java:428)
|
at org.bson.codecs.StringCodec.decode(StringCodec.java:39)
|
at org.bson.codecs.StringCodec.decode(StringCodec.java:28)
|
at com.mongodb.operation.CommandResultArrayCodec.decode(CommandResultArrayCodec.java:48)
|
at com.mongodb.operation.CommandResultDocumentCodec.readValue(CommandResultDocumentCodec.java:53)
|
at org.bson.codecs.BsonDocumentCodec.decode(BsonDocumentCodec.java:84)
|
at org.bson.codecs.BsonDocumentCodec.decode(BsonDocumentCodec.java:41)
|
at com.mongodb.connection.ReplyMessage.<init>(ReplyMessage.java:57)
|
at com.mongodb.connection.CommandProtocol.getResponseDocument(CommandProtocol.java:139)
|