Will MongoDB Java driver 4.0+ retry DBCursor.next()?

Viewed 177

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()?

2 Answers

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())
}

Related