[JAVA-480] DBCursor.count() <> DBCursor.toArray().size() using with $max Created: 30/Nov/11  Updated: 23/Jun/15  Resolved: 23/Jun/15

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

Type: Bug Priority: Minor - P4
Reporter: Uladzimir Mihura Assignee: Unassigned
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified


 Description   

Code:

public class Test {
    public static void main(String[] args) throws UnknownHostException {
        Mongo m = new Mongo();
        DBCollection collection = m.getDB("test").getCollection("tmp");
        collection.drop();
        collection.ensureIndex("length");
        for (int i = 0; i < 10; i++) {
            DBObject object = new BasicDBObject("_id", i);
            object.put("length", (int) (Math.random() * 100));
            collection.insert(object);
        }
        DBCursor cursor = collection.find().addSpecial("$max", new BasicDBObject("length", 10));
        System.out.println("cursor.count - " + cursor.count());
        System.out.println("cursor.toArray.size - " + cursor.toArray().size());
    }
}

Result:

cursor.count - 10
cursor.toArray.size - 0



 Comments   
Comment by Jeffrey Yemin [ 10/Mar/12 ]

Does toArray work as you expect when not using $max?

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