batchSize vs limit

167 views
Skip to first unread message

Dustin Norlander

unread,
Apr 7, 2010, 2:22:58 PM4/7/10
to mongod...@googlegroups.com
Sorry if this has been answered elsewhere, I've searched through the
list and docs and not found much.

I had assumed batchSize was the number of objects downloaded from the
server in a single batch (to avoid tons of synchronous requests). But
it seems to also set the 'limit' param.

the code in question (java):

cur.batchSize(500);
cur.limit(1000);
while(cur.hasNext()) {
DBObject obj = cur.next()
//do something
}

In this example I only get 500 results back. Easy enough fix is to
set batchSize = limit. I'm just confused as to the logic.

Eliot Horowitz

unread,
Apr 7, 2010, 5:26:27 PM4/7/10
to mongod...@googlegroups.com
You're understanding is correct.
You should get 1000 results in 2 batches of 500 (internally)

There is in fact a unit test exactly for that
http://github.com/mongodb/mongo-java-driver/blob/master/src/test/com/mongodb/DBCursorTest.java#L153-162

If you can provide a full example that fails, can take a look.

> --
> You received this message because you are subscribed to the Google Groups "mongodb-user" group.
> To post to this group, send email to mongod...@googlegroups.com.
> To unsubscribe from this group, send email to mongodb-user...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/mongodb-user?hl=en.
>
>

Reply all
Reply to author
Forward
0 new messages