[JAVA-826] Array.0 exists true doesn't work correct Created: 09/May/13  Updated: 25/Jun/13  Resolved: 23/May/13

Status: Closed
Project: Java Driver
Component/s: API
Affects Version/s: 2.11.1
Fix Version/s: None

Type: Bug Priority: Critical - P2
Reporter: Robert Reiz Assignee: Unassigned
Resolution: Cannot Reproduce Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

Mac OS X



 Description   

In one collection I have an embedded array of ObjectIds. The name of the array is "user_ids". I wrote a query to fetch all elements from the collection where the array has at least 1 element. The native MongoDB query looks like this:

db.mycollection.find( {"user_ids.0" :

{ "$exists" : true }

} )

and it works fine. It returns 2 elements. In Java I did it like this:

query.put("user_ids.0", new BasicDBObject("$exists", Boolean.TRUE) );

Unfortunately it returns only 1 element. 1 is missing.
It looks like a bug.



 Comments   
Comment by Jeffrey Yemin [ 23/May/13 ]

Since we haven't heard back from you, we're going to assume this is not a bug, but please feel free to re-open.

Comment by Jeffrey Yemin [ 09/May/13 ]

I tried to reproduce this, but could not. This code:

        MongoClient client = new MongoClient();
        DBCollection c = client.getDB("test").getCollection("JAVA826");
        c.drop();
 
        c.insert(new BasicDBObject());
        c.insert(new BasicDBObject("user_ids", Arrays.asList()));
        c.insert(new BasicDBObject("user_ids", Arrays.asList(new ObjectId())));
        c.insert(new BasicDBObject("user_ids", Arrays.asList(new ObjectId(), new ObjectId())));
 
        final BasicDBObject query = new BasicDBObject("user_ids.0", new BasicDBObject("$exists", Boolean.TRUE));
        System.out.println(c.count(query));
        System.out.println(c.find(query).toArray().size());

Produced this output:

2
2

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