Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

like image 482
ikh Avatar asked Dec 11 '20 19:12

ikh


People also ask

What is MongoDB driver sync?

The MongoDB Driver mongodb-driver-sync is the synchronous Java driver containing only the generic MongoCollection interface that complies with a new cross-driver CRUD specification. It does not include the legacy API (e.g. DBCollection ).

Is Java compatible with MongoDB?

To interact with MongoDB from our Java application, we will use a piece of software called the Java Driver, which is an official and recommended MongoDB driver application for the Java language.

How does MongoDB connect to MongoClient in Java?

To connect: MongoClient client = MongoClients. create("<<MongoDB URI>>"); To connect to MongoDB on your local instance and default port, you can just omit the URI part of the above, or use a URI like 'mongodb://localhost:27017'.


1 Answers

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

like image 175
s7vr Avatar answered Oct 18 '22 01:10

s7vr