Uploaded image for project: 'Java Driver'
  1. Java Driver
  2. JAVA-402

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

    XMLWordPrintableJSON

Details

    • Icon: Bug Bug
    • Resolution: Done
    • Icon: Major - P3 Major - P3
    • None
    • 2.6.3
    • None
    • None
    • Mongo 1.8.2
      Java Driver 2.6.3
      windows 32-bit

    Description

      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
      }

      Attachments

        Activity

          People

            antoine Antoine Girbal
            westernsam sam owen
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: