diff --git a/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/mongo/MongoDocumentStore.java b/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/mongo/MongoDocumentStore.java index 5025fe7fe3e..5d7de2d8639 100644 --- a/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/mongo/MongoDocumentStore.java +++ b/oak-store-document/src/main/java/org/apache/jackrabbit/oak/plugins/document/mongo/MongoDocumentStore.java @@ -246,6 +246,19 @@ enum DocumentReadPreference { private final long maxQueryTimeMS = Long.getLong("oak.mongo.maxQueryTimeMS", TimeUnit.MINUTES.toMillis(1)); + /** + * Flag to control the cursor timeout behavior in MongoDB. + *

+ * If set to true, the server will not close the cursor if no operations are performed for a certain period of time. + * This can be useful for long running queries or when the client needs to retain the cursor for a longer period. + *

+ * Default value is false, meaning the server will automatically close idle cursors after a default server-side + * timeout. + * See: https://www.mongodb.com/docs/manual/reference/method/cursor.noCursorTimeout + */ + private final boolean noCursorTimeout = + Boolean.getBoolean("oak.mongo.noCursorTimeout"); + /** * The number of documents to put into one bulk update. *

@@ -867,6 +880,10 @@ && canUseModifiedTimeIdx(startValue)) { result.maxTime(maxQueryTime, TimeUnit.MILLISECONDS); } + if (noCursorTimeout) { + result.noCursorTimeout(noCursorTimeout); + } + try (MongoCursor cursor = result.iterator()) { for (int i = 0; i < limit && cursor.hasNext(); i++) { BasicDBObject o = cursor.next();