Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-4193

Cursor closed if limit is 1

    • Type: Icon: Bug Bug
    • Resolution: Cannot Reproduce
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: None
    • Component/s: Sharding
    • Labels:
    • Environment:
      any
    • ALL

      If limit is 1, and batchsize is 0, DBApiLayer.chooseBatchSize will return -1, and the cursor will be closed as a result.

      in DBApiLayer.chooseBatchSize, I see
      if (res == 1)

      { // optimization: use negative batchsize to close cursor res = -1; }

      Code to replicate
      I have 4 entries in the collection

      DB m = Mongo.connect(new DBAddress("host", "dbname"));

      DBCursor c1 = m.getCollection("mycoll").find();
      int count1 = 0;
      while (c1.hasNext())

      { c1.next(); count1++; }

      System.out.println("Count 1 is: " + count1);

      DBCursor c2 = m.getCollection("buttons").find().skip(2).limit(1);
      int count2 = 0;
      while (c2.hasNext())

      { c2.next(); count2++; }

      System.out.println("Count 2 is: " + count2);

      Output:
      Count 1 is: 4
      Count 2 is: 0

            Assignee:
            antoine Antoine Girbal
            Reporter:
            yalexander Alex Yakushev
            Votes:
            6 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: