[JAVA-2429] DBCollection.distinct() fails when a null value is in the result Created: 20/Jan/17  Updated: 24/Jan/17  Resolved: 24/Jan/17

Status: Closed
Project: Java Driver
Component/s: Query Operations
Affects Version/s: 3.4.0
Fix Version/s: 3.4.2

Type: Bug Priority: Major - P3
Reporter: Jan S. Assignee: Jeffrey Yemin
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified


 Description   

When I execute the command db.getCollection("collname").distinct("fieldname"); on a collection that contains a document like

{
  "_id": "...",
  "fieldname": null 
}

Exception in thread "main" java.lang.IllegalArgumentException: The value for key value can not be null
	at org.bson.BsonDocument.put(BsonDocument.java:721)
	at org.bson.BsonDocument.<init>(BsonDocument.java:83)
	at com.mongodb.DBCollection$1.apply(DBCollection.java:1185)
	at com.mongodb.DBCollection$1.apply(DBCollection.java:1182)
	at com.mongodb.MappingIterable$1.apply(MappingIterable.java:53)
	at com.mongodb.OperationIterable.forEach(OperationIterable.java:73)
	at com.mongodb.MappingIterable.forEach(MappingIterable.java:50)
	at com.mongodb.MappingIterable.into(MappingIterable.java:60)
	at com.mongodb.DBCollection.distinct(DBCollection.java:1189)
	at com.mongodb.DBCollection.distinct(DBCollection.java:1161)
	at com.mongodb.DBCollection.distinct(DBCollection.java:1136)
	at com.mongodb.DBCollection.distinct(DBCollection.java:1124)
	at DbBugTest.main(DbBugTest.java:13)



 Comments   
Comment by Jeffrey Yemin [ 24/Jan/17 ]

master:

commit 8cfd49e4a83866b9b5f01eaf02256057a2e89c26
Author: Jeff Yemin <jeff.yemin@10gen.com>
Date: Tue Jan 24 09:21:05 2017 -0500

JAVA-2429: Handle null values in DBCollection distinct implementation

Comment by Jeffrey Yemin [ 24/Jan/17 ]

3.4.x:

commit 3b2868465e856681d0096ee3e0d9cc4bd5ac2ccb
Author: Jeff Yemin <jeff.yemin@10gen.com>
Date: Tue Jan 24 09:21:05 2017 -0500

JAVA-2429: Handle null values in DBCollection distinct implementation

Comment by Ross Lawley [ 20/Jan/17 ]

Thanks the ticket mango and the test data to reproduce the issue.

We'll look into fixing in the next release, in the meantime a work around would be to use the aggregation framework.

Generated at Thu Feb 08 08:57:11 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.