I have a cursor in casbah, returned from a query. If I iterate over the cursor I get a certain number of results, x. If I execute the same query and do a toList on the cursor, I get list of size y, a different number. Why?
I'm calling this from a test case that has just wriiten a few hundred rows to the collection using the default WriteConcern. I understand there could be some latency with the write. What I don't understand is the different sizes of the cursor: I iterate vs toList. Aren't they basically doing the same thing (presuming I'm yielding a List from my iteration)?
val cur = findCursor(query, orderBy).skip(skip).limit(chunkSize * -1) // results size x if I iterate cur
val ret = cur.toList.map( dbo => SJ.readDB[T](dbo) ). // List size y here after toList
They should be the same as they both iterate in the same way underneath, heres an example:
You could get different results if new documents had been added to the database between counts or if you partially iterate the cursor then convert to list eg:
The problem was found. The issue lay with the negative value passed to the limit function. I don't fully understand the semantic difference between pos/neg values to limit, or why they'd return different counts, but switching to a positive number returned the result count expected.