[JAVA-1250] result set does not include all values Created: 18/May/14  Updated: 20/May/14  Resolved: 20/May/14

Status: Closed
Project: Java Driver
Component/s: JSON
Affects Version/s: 2.11.2
Fix Version/s: None

Type: Bug Priority: Major - P3
Reporter: Ron Natan Assignee: Ross Lawley
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

2.4 server; 2.11 driver - may be present in other versions - I did not check


Attachments: File foo.json    

 Description   

I have a document that has this field:

...,
"boolean_array" : [
true,
null
],...

When I read it using the python driver I indeed get this data as is.

But when I read it using the Java driver I get this:

..., "boolean_array" : [ true] ,...



 Comments   
Comment by Ross Lawley [ 20/May/14 ]

Marking as "Works as Designed" as there is no support for the undefined type in the java driver.

Comment by Ross Lawley [ 20/May/14 ]

Thanks rbennata the foo.json is the clue to why we are seeing conflicting results. The boolean_array is not as it seems:

"boolean_array" : [ true, { "$undefined" : true } ]

According to the BSON spec (http://bsonspec.org/spec.html) the Undefined type has been deprecated and there is no support for in the Java driver as there is no undefined equivalent mapping in java. The shell translates undefined as null and there is a ticket to fix that: SERVER-6102

I would advise not using the undefined type as it has been deprecated but if that isn't feasible then you will have to code your own decoder factory and then set it like so:

collection.setDBDecoderFactory(MyDecoder.FACTORY);

A minimal example that has defined handling for undefined and factory is available on github in the horn of mongo repo.

Comment by Ron Natan [ 20/May/14 ]

I can reproduce and am attaching a JSON output file so hopefully it reproduces for you too.

Using your program:

public static void main(String[] args) throws UnknownHostException {
        MongoClient client = new MongoClient("localhost", 47017);
        DBObject doc = client.getDB("test").getCollection("foo").findOne();
        System.out.println(doc);    
}

Output in the shell and Java below show diff (hard to read because long).

Specifically, in shell:
"boolean_array" : [ true, null ]

In Java:
"boolean_array" : [ true]

Attaching foo.json - please import this document and hopefully it happens to you too.

> db.foo.find()
{ "_id" : ObjectId("521a885fc2d16d7a01353a7f"), "integer" : 7, "longinteger" : [ 7000, 7001, 7002 ], "floatingpoint" : [ 5.5, 6.6, 7.7 ], "real_date" : ISODate("2013-08-25T22:42:39.054Z"), "regex_sting" : /foo/i, "uncode_string" : "foo", "boolean_value" : true, "compound_timestamp" : { "t" : 5, "i" : 4 }, "subdoc" : { "subdoc_regex_sting" : /foo/i, "subdoc_uncode_string" : "foo", "subdoc_boolean_value" : true }, "vartype_aray " : [ 	1.5, true, 	"1", 	/bar/i, 	{ 	"t" : 7, 	"i" : 8 }, 	ISODate("2013-08-25T22:42:39.054Z"), 	70, 	7000, 	{ 	"subdoc_field" : 1 } ], "integer_array" : [ 1, 2, 3 ], "uncode_array" : [ "foo", "bar", "baz" ], 
 
"boolean_array" : [ true, null ], 
 
"object_array" : [ 	{ 	"name" : "yosefa", 	"age" : 38 }, 	{ 	"name" : "hedva", 	"age" : 34 }, 	{ 	"name" : "yaacov", 	"age" : 32 } ], "date_array" : [ 	ISODate("2013-10-21T11:53:22.121Z"), 	ISODate("2012-09-21T11:35:33.131Z"), 	ISODate("2011-08-21T11:44:00.141Z") ], "id_array" : [ 	ObjectId("521a885fc2d16d7a01353a80"), 	ObjectId("521a885fc2d16d7a01353a81"), 	ObjectId("521a885fc2d16d7a01353a82") ], "timestamp_array" : [ { "t" : 5, "i" : 4 }, { "t" : 7, "i" : 6 }, { "t" : 1, "i" : 2 } ], "regex_array" : [ 	/.*Damn.*/, 	/.*FTL.*/, 	/.*MUST DIE.*/, 	/.*STING.*/, 	/.*WTF.*/, 	/.*an issue.*/, 	/.*angered.*/, 	/.*angry.*/, 	/.*annoyed.*/, 	/.*annoying.*/, 	/.*anti.*/, 	/.*anxiety.*/, 	/.*anxious.*/, 	/.*arent.*/, 	/.*arrogant.*/, 	/.*ashamed.*/i, 	/.*awful.*/, 	/.*bad.*/, 	/.*bewildered.*/, 	/.*blues.*/, 	/.*bored.*/, 	/.*brainwashed.*/, 	/.*buggy.*/, 	/.*bullshit.*/, 	/.*cant send.*/, 	/.*clumsy.*/, 	/.*combative.*/, 	/.*commie.*/, 	/.*communist.*/, 	/.*condemned.*/, 	/.*confused.*/i ] }

This is the output from your program:

{ "_id" : { "$oid" : "521a885fc2d16d7a01353a7f"} , "integer" : 7 , "longinteger" : [ 7000 , 7001 , 7002] , "floatingpoint" : [ 5.5 , 6.6 , 7.7] , "real_date" : { "$date" : "2013-08-25T22:42:39.054Z"} , "regex_sting" : { "$regex" : "foo" , "$options" : "i"} , "uncode_string" : "foo" , "boolean_value" : true , "compound_timestamp" : { "$ts" : 5 , "$inc" : 4} , "subdoc" : { "subdoc_regex_sting" : { "$regex" : "foo" , "$options" : "i"} , "subdoc_uncode_string" : "foo" , "subdoc_boolean_value" : true} , "vartype_aray " : [ 1.5 , true , "1" , { "$regex" : "bar" , "$options" : "i"} , { "$ts" : 7 , "$inc" : 8} , { "$date" : "2013-08-25T22:42:39.054Z"} , 70 , 7000 , { "subdoc_field" : 1}] , "integer_array" : [ 1 , 2 , 3] , "uncode_array" : [ "foo" , "bar" , "baz"] , 
 
"boolean_array" : [ true] , 
 
"object_array" : [ { "name" : "yosefa" , "age" : 38} , { "name" : "hedva" , "age" : 34} , { "name" : "yaacov" , "age" : 32}] , "date_array" : [ { "$date" : "2013-10-21T11:53:22.121Z"} , { "$date" : "2012-09-21T11:35:33.131Z"} , { "$date" : "2011-08-21T11:44:00.141Z"}] , "id_array" : [ { "$oid" : "521a885fc2d16d7a01353a80"} , { "$oid" : "521a885fc2d16d7a01353a81"} , { "$oid" : "521a885fc2d16d7a01353a82"}] , "timestamp_array" : [ { "$ts" : 5 , "$inc" : 4} , { "$ts" : 7 , "$inc" : 6} , { "$ts" : 1 , "$inc" : 2}] , "regex_array" : [ { "$regex" : ".*Damn.*"} , { "$regex" : ".*FTL.*"} , { "$regex" : ".*MUST DIE.*"} , { "$regex" : ".*STING.*"} , { "$regex" : ".*WTF.*"} , { "$regex" : ".*an issue.*"} , { "$regex" : ".*angered.*"} , { "$regex" : ".*angry.*"} , { "$regex" : ".*annoyed.*"} , { "$regex" : ".*annoying.*"} , { "$regex" : ".*anti.*"} , { "$regex" : ".*anxiety.*"} , { "$regex" : ".*anxious.*"} , { "$regex" : ".*arent.*"} , { "$regex" : ".*arrogant.*"} , { "$regex" : ".*ashamed.*" , "$options" : "i"} , { "$regex" : ".*awful.*"} , { "$regex" : ".*bad.*"} , { "$regex" : ".*bewildered.*"} , { "$regex" : ".*blues.*"} , { "$regex" : ".*bored.*"} , { "$regex" : ".*brainwashed.*"} , { "$regex" : ".*buggy.*"} , { "$regex" : ".*bullshit.*"} , { "$regex" : ".*cant send.*"} , { "$regex" : ".*clumsy.*"} , { "$regex" : ".*combative.*"} , { "$regex" : ".*commie.*"} , { "$regex" : ".*communist.*"} , { "$regex" : ".*condemned.*"} , { "$regex" : ".*confused.*" , "$options" : "i"}]}

Comment by Jeffrey Yemin [ 19/May/14 ]

I'm not able to reproduce this.

I inserted a document via the shell:

> db.test.insert({'ba' : [true, null] } )
WriteResult({ "nInserted" : 1 })
> db.test.findOne()
{ "_id" : ObjectId("537a0bc3129d71c38fff9aa6"), "ba" : [ true, null ] }

and then wrote the following Java program:

public class JAVA1250 {
    public static void main(String[] args) throws UnknownHostException {
        MongoClient client = new MongoClient();
        DBObject doc = client.getDB("test").getCollection("test").findOne();
        System.out.println(doc);
 

On execution it prints the following:

{ "_id" : { "$oid" : "537a0bc3129d71c38fff9aa6"} , "ba" : [ true ,  null ]}

Inspecting in the IntelliJ IDEA debugger, by the way, is a bit confusing because by default it hides null array elements, but I can see that the null value is definitely there.

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