[JAVA-402] Only 1 batch is returned if batchSize on cursor is set and results are sorted Created: 27/Jul/11  Updated: 19/Oct/16  Resolved: 24/Oct/11

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

Type: Bug Priority: Major - P3
Reporter: sam owen Assignee: Antoine Girbal
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

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
}



 Comments   
Comment by alex giamas [ 12/Jan/12 ]

That's great news Scott, thanks!

Comment by Scott Hernandez (Inactive) [ 12/Jan/12 ]

Let me linked the server issue. 2.1.x is the current dev release. I expect a fix in 2.2.0 which is the next production release.

Comment by alex giamas [ 12/Jan/12 ]

expected fix version? 2.2.1 maybe?

Comment by Scott Hernandez (Inactive) [ 12/Jan/12 ]

This is still a server issue, and not a driver one.

Comment by alex giamas [ 12/Jan/12 ]

Looks like this hasn't been fixed and should be reopened. We bumped into it again with DB 2.0.2 and Java driver 2.7.2. Looks like we are in the same boat as this guy:
http://comments.gmane.org/gmane.comp.db.mongodb.user/56322

i.e. We are using an index for the query but it's doing scanAndOrder:true, with sort() we only get the first batch of results, without sort we are fine.

Comment by Scott Hernandez (Inactive) [ 24/Oct/11 ]

This was a server problem and has been fixed.

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