I know Mongo Java driver will retry collection.find(), and most other read operations, per Mongo docs.
But I can't see anywhere in docs or in the driver source - will it retry DBCursor.next() or DBCursor.hasNext()?
I know Mongo Java driver will retry collection.find(), and most other read operations, per Mongo docs.
But I can't see anywhere in docs or in the driver source - will it retry DBCursor.next() or DBCursor.hasNext()?
No, it will not retry cursor based reads.
Cursor.getMore() cannot be retried because of the inability for the client to discern if the cursor was advanced. In other words, since the driver does not know if the original getMore() succeeded or not, the driver cannot reliably know if results might be inadvertently skipped.
More details here - https://github.com/mongodb/specifications/blob/master/source/retryable-reads/retryable-reads.rst#implementing-retryable-reads
collection.find() will retry the whole collection, that's clear.
Now, if you are using a while operation, you can then use hasNext() operation in order to break the operation when there are not more elements.
while(cursor.hasNext()){
system.out.println(cursor.next())
}