DBCursor.count() <> DBCursor.toArray().size() using with $max

XMLWordPrintableJSON

    • Type: Bug
    • Resolution: Done
    • Priority: Minor - P4
    • None
    • Affects Version/s: None
    • Component/s: Query Operations
    • None
    • None
    • None
    • None
    • None
    • None
    • None
    • None

      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
      

            Assignee:
            Unassigned
            Reporter:
            Uladzimir Mihura (Inactive)
            None
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: