I have some code like:
cursor = self.db.coll.find({})
cursor.batch_size(100)
last = next(cursor)
while True:
...
while a>b:
last = next(cursor)
...
Except that I want to use an idiom to pull from cursor with next, rather than use for cycle. What I see is that next raises StopIteration after the 100 block, where I expected it to refresh by the end of the block. If I remove the batch_size it works as expected, but I need to bring down the batch_size. I looked at the source code of the driver an it has something like:
def next(self):
if self.__empty:
raise StopIteration
db = self.__collection.database
if len(self.__data) or self._refresh():
next = db._fix_outgoing(self.__data.pop(0), self.__collection)
else:
raise StopIteration
return next
I don't get the purpose of that self.__empty which is explained as some ugly way to support some slicing. What I see on the next line makes more sense: if it has data or if refreshes successfully otherwise it goes on, but my invocation doesn't seem to reach that point... What do I have to do for the next() to continue pulling the next batch ?