From eb75736195da7fd845bdcf109c85b4b867d93f46 Mon Sep 17 00:00:00 2001 From: Angela Date: Thu, 24 Jul 2025 16:48:08 -0400 Subject: [PATCH 1/2] add retryable section --- source/crud/configure.txt | 42 ++++++++++++++++++++++++++++--- source/includes/configure-crud.kt | 17 +++++++++++++ 2 files changed, 56 insertions(+), 3 deletions(-) diff --git a/source/crud/configure.txt b/source/crud/configure.txt index 175dd382..0d65cae9 100644 --- a/source/crud/configure.txt +++ b/source/crud/configure.txt @@ -307,17 +307,16 @@ tab to see corresponding code for each approach: :tabid: settings .. literalinclude:: /includes/configure-crud.kt - :language: rust + :language: kotlin :dedent: :start-after: start-local-threshold-settings :end-before: end-local-threshold-settings - .. tab:: Connection URI :tabid: uri .. literalinclude:: /includes/configure-crud.kt - :language: rust + :language: kotlin :dedent: :start-after: start-local-threshold-uri :end-before: end-local-threshold-uri @@ -325,6 +324,43 @@ tab to see corresponding code for each approach: In the preceding example, the {+driver-short+} distributes reads among matching members within 35 milliseconds of the closest member's ping time. +Retryable Reads and Writes +-------------------------- + +{+driver-short+} automatically retries certain read and write operations a single time +if they fail due to a network or server error. + +You can explicitly disable retryable reads or retryable writes by setting the ``retryReads`` or +``retryWrites`` option to ``False`` in a ``MongoClientSettings`` instance. You can also +set the ``retryReads`` or ``retryWrites`` options in your connection URI. + +The following example sets both retryable reads and retryable writes to ``False``. Select the :guilabel:`MongoClientSettings` or :guilabel:`Connection URI` +tab to see corresponding code for each approach: + +.. tabs:: + + .. tab:: MongoClientSettings + :tabid: settings + + .. literalinclude:: /includes/configure-crud.kt + :language: kotlin + :dedent: + :start-after: start-retryable-reads-writes + :end-before: end-retryable-reads-writes + + .. tab:: Connection URI + :tabid: uri + + .. literalinclude:: /includes/configure-crud.kt + :language: kotlin + :dedent: + :start-after: start-retryable-reads-writes-uri + :end-before: end-retryable-reads-writes-uri + +To learn more about supported retryable read operations, see :manual:`Retryable Reads ` +in the {+mdb-server+} manual. To learn more about supported retryable write +operations, see :manual:`Retryable Writes ` in the {+mdb-server+} manual. + API Documentation ----------------- diff --git a/source/includes/configure-crud.kt b/source/includes/configure-crud.kt index 3d5150dd..73216b18 100644 --- a/source/includes/configure-crud.kt +++ b/source/includes/configure-crud.kt @@ -106,6 +106,23 @@ fun main() { val latencyClient2 = MongoClient.create(latencySettings) // end-local-threshold-settings + // Disable retryable reads and writes using MongoClientSettings builder + // start-retryable-reads-writes + val retrySettings = MongoClientSettings.builder() + .applyConnectionString(ConnectionString("mongodb://localhost:27017/")) + .retryReads(false) // Disables automatic retries of read operations + .retryWrites(false) // Disables automatic retries of write operations + .build() + + val retryClient = MongoClient.create(retrySettings) + + // end-retryable-reads-writes + + // start-retryable-reads-writes-uri + val retryUri = "mongodb://localhost:27017/?retryReads=false&retryWrites=false" + val retryUriClient = MongoClient.create(retryUri) + // end-retryable-reads-writes-uri + // Close the MongoClient connection mongoClient.close() } From fc341f5887af01214e3676860be8928a486f826f Mon Sep 17 00:00:00 2001 From: Angela Date: Fri, 25 Jul 2025 09:45:01 -0400 Subject: [PATCH 2/2] mb feedback --- source/crud/configure.txt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/source/crud/configure.txt b/source/crud/configure.txt index 0d65cae9..fc60312b 100644 --- a/source/crud/configure.txt +++ b/source/crud/configure.txt @@ -327,14 +327,14 @@ within 35 milliseconds of the closest member's ping time. Retryable Reads and Writes -------------------------- -{+driver-short+} automatically retries certain read and write operations a single time +The {+driver-short+} automatically retries certain read and write operations a single time if they fail due to a network or server error. You can explicitly disable retryable reads or retryable writes by setting the ``retryReads`` or -``retryWrites`` option to ``False`` in a ``MongoClientSettings`` instance. You can also +``retryWrites`` option to ``false`` in a ``MongoClientSettings`` instance. You can also set the ``retryReads`` or ``retryWrites`` options in your connection URI. -The following example sets both retryable reads and retryable writes to ``False``. Select the :guilabel:`MongoClientSettings` or :guilabel:`Connection URI` +The following example sets both retryable reads and retryable writes to ``false``. Select the :guilabel:`MongoClientSettings` or :guilabel:`Connection URI` tab to see corresponding code for each approach: .. tabs::