I'm trying to set the QUERYOPTION_NOTIMEOUT flag when doing a find() query. The flag overrides the default 10 minutes timeout on MongoCursor.
According to the Documentation find() should return a DBCursor:
DBCursor cursor = collection.find(query);
And then I can do
cursor.addOption(Bytes.QUERYOPTION_NOTIMEOUT);
But find() actually returns FindIterableImpl / which doesn't have the addOption() method.
Here's the entire method for context:
public static MongoCursor getSomethingFromDB(String something) {
MongoCollection collection = getCollectionForClass(BlogPost.class);
return collection.find(and(exists("a", false), eq("other", something))).iterator();
}
The way to do this on the version 3 of the mongo-java driver is:
collection.find(and(exists("a", false), eq("other", lang))).noCursorTimeout(true).iterator();
Apparently the
cursor.addOption(Bytes.QUERYOPTION_NOTIMEOUT);
is from the V2 API and the V3 documentation is outdated
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With