Only 1 batch is returned if batchSize on cursor is set and results are sorted

XMLWordPrintableJSON

    • Type: Bug
    • Resolution: Done
    • Priority: Major - P3
    • None
    • Affects Version/s: 2.6.3
    • Component/s: None
    • None
    • Environment:
      Mongo 1.8.2
      Java Driver 2.6.3
      windows 32-bit
    • None
    • None
    • None
    • None
    • None
    • None
    • None

      import com.mongodb.*;
      import org.junit.Test;
      import java.net.UnknownHostException;

      public class MongoDriverSortAndBatchSizeTest {
      @Test
      public void batchSizeAndSortBy() throws UnknownHostException {
      Mongo mongo = new Mongo(new ServerAddress("localhost",
      27017));
      DB test = mongo.getDB("test");
      DBCollection collection = test.getCollection("test");
      // add 100 documents
      for (int i = 0; i < 1000; i++)

      { collection.save(new BasicDBObject("sortby", i)); }


      //get the cursor - batchsize = 500
      DBCursor dbCursor = collection.find(new BasicDBObject())
      .batchSize(500)
      .sort(new BasicDBObject("sortby", 1));
      int counter = 0;
      try {
      //consume cursor
      while (dbCursor.hasNext())

      { DBObject next = dbCursor.next(); counter++; }


      } finally

      { dbCursor.close(); }


      assertEquals(1000, counter); //fails - counter is 500
      }

            Assignee:
            Antoine Girbal (Inactive)
            Reporter:
            sam owen
            None
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: