From d5659e542b3883172a35454e352ccdbac09a6626 Mon Sep 17 00:00:00 2001 From: Michael Morisi Date: Thu, 10 Apr 2025 10:29:48 -0400 Subject: [PATCH 1/4] DOCSP-49095: Retryable Reads and Writes --- source/crud/configure.txt | 20 +++++++++++++++++++ .../code-examples/ReplicaSetConfigs.cs | 15 +++++++++++--- 2 files changed, 32 insertions(+), 3 deletions(-) diff --git a/source/crud/configure.txt b/source/crud/configure.txt index 01ea55ed..be5f64b8 100644 --- a/source/crud/configure.txt +++ b/source/crud/configure.txt @@ -191,6 +191,26 @@ The following example sets the read preference to ``ReadPreference.Secondary`` f For more information about read preference, see :manual:`Read Preference ` in the {+mdb-server+} manual. +Retryable Reads and Writes +-------------------------- + +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`` options on a ``MongoClientSettings`` object and passing this object to the +``MongoClient`` constructor. The following example disables retryable reads and writes for +a client: + +.. literalinclude:: /includes/fundamentals/code-examples/ReplicaSetConfigs.cs + :start-after: start-retry-reads-writes + :end-before: end-retry-reads-writes + :language: csharp + :dedent: + +To learn more about supported retryable reads and retryable writes, see :manual:`Retryable Reads ` +and :manual:`Retryable Writes ` in the {+mdb-server+} manual. + API Documentation ----------------- diff --git a/source/includes/fundamentals/code-examples/ReplicaSetConfigs.cs b/source/includes/fundamentals/code-examples/ReplicaSetConfigs.cs index fcb35edd..6e8086fe 100644 --- a/source/includes/fundamentals/code-examples/ReplicaSetConfigs.cs +++ b/source/includes/fundamentals/code-examples/ReplicaSetConfigs.cs @@ -8,7 +8,7 @@ public static void Main(string[] args) var client = new MongoClient("mongodb://localhost:27017"); { // start-write-concern-client - var mongoClientSettings = MongoClientSettings.FromConnectionString(""); + var mongoClientSettings = MongoClientSettings.FromConnectionString(""); mongoClientSettings.WriteConcern = WriteConcern.WMajority; var mongoClient = new MongoClient(mongoClientSettings); // end-write-concern-client @@ -24,7 +24,7 @@ public static void Main(string[] args) { // start-read-concern-client - var mongoClientSettings = MongoClientSettings.FromConnectionString(""); + var mongoClientSettings = MongoClientSettings.FromConnectionString(""); mongoClientSettings.ReadConcern = ReadConcern.Majority; var mongoClient = new MongoClient(mongoClientSettings); // end-read-concern-client @@ -40,7 +40,7 @@ public static void Main(string[] args) { // start-read-preference-client - var mongoClientSettings = MongoClientSettings.FromConnectionString(""); + var mongoClientSettings = MongoClientSettings.FromConnectionString(""); mongoClientSettings.ReadPreference = ReadPreference.Secondary; var mongoClient = new MongoClient(mongoClientSettings); // end-read-preference-client @@ -53,5 +53,14 @@ public static void Main(string[] args) .WithReadPreference(ReadPreference.Secondary); // end-read-preference-collection } + + { + // start-retry-reads-writes + var mongoClientSettings = MongoClientSettings.FromConnectionString(""); + mongoClientSettings.RetryReads = false; + mongoClientSettings.RetryWrites = false; + var mongoClient = new MongoClient(mongoClientSettings); + // end-retry-reads-writes + } } } \ No newline at end of file From d33baac9136c40bb8f251f26559ba6e105c7d111 Mon Sep 17 00:00:00 2001 From: Michael Morisi Date: Thu, 10 Apr 2025 10:56:22 -0400 Subject: [PATCH 2/4] LM feedback --- source/crud/configure.txt | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/source/crud/configure.txt b/source/crud/configure.txt index be5f64b8..e40f510c 100644 --- a/source/crud/configure.txt +++ b/source/crud/configure.txt @@ -205,10 +205,12 @@ a client: .. literalinclude:: /includes/fundamentals/code-examples/ReplicaSetConfigs.cs :start-after: start-retry-reads-writes :end-before: end-retry-reads-writes + :emphasize-lines: 2-3 :language: csharp :dedent: -To learn more about supported retryable reads and retryable writes, see :manual:`Retryable Reads ` +To learn more about supported retryable read and retryable write operations, see +:manual:`Retryable Reads ` and :manual:`Retryable Writes ` in the {+mdb-server+} manual. API Documentation From 176a37d64a11f6e2381096af1622bec5586391e9 Mon Sep 17 00:00:00 2001 From: Michael Morisi Date: Wed, 16 Apr 2025 09:17:17 -0400 Subject: [PATCH 3/4] Tech feedback --- source/crud/configure.txt | 30 +++++++++++++++++-- .../code-examples/ReplicaSetConfigs.cs | 8 +++++ 2 files changed, 36 insertions(+), 2 deletions(-) diff --git a/source/crud/configure.txt b/source/crud/configure.txt index e40f510c..675a0e32 100644 --- a/source/crud/configure.txt +++ b/source/crud/configure.txt @@ -199,8 +199,12 @@ 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`` options on a ``MongoClientSettings`` object and passing this object to the -``MongoClient`` constructor. The following example disables retryable reads and writes for -a client: +``MongoClient`` constructor. You can also set the ``retryReads`` or ``retryWrites`` options +in a connection string. + +The following example disables retryable reads and writes for +a client. Select the :guilabel:`MongoClientSettings` or :guilabel:`Connection String` +tab to see the corresponding code. .. literalinclude:: /includes/fundamentals/code-examples/ReplicaSetConfigs.cs :start-after: start-retry-reads-writes @@ -209,6 +213,28 @@ a client: :language: csharp :dedent: +.. tabs:: + + .. tab:: MongoClientSettings + :tabid: mongoclientsettings + + .. literalinclude:: /includes/fundamentals/code-examples/ReplicaSetConfigs.cs + :start-after: start-retry-reads-writes + :end-before: end-retry-reads-writes + :emphasize-lines: 2-3 + :language: csharp + :dedent: + + .. tab:: Connection String + :tabid: connectionstring + + .. literalinclude:: /includes/fundamentals/code-examples/ReplicaSetConfigs.cs + :start-after: start-retry-reads-writes + :end-before: end-retry-reads-writes + :emphasize-lines: 1 + :language: csharp + :dedent: + To learn more about supported retryable read and retryable write operations, see :manual:`Retryable Reads ` and :manual:`Retryable Writes ` in the {+mdb-server+} manual. diff --git a/source/includes/fundamentals/code-examples/ReplicaSetConfigs.cs b/source/includes/fundamentals/code-examples/ReplicaSetConfigs.cs index 6e8086fe..cf7c2163 100644 --- a/source/includes/fundamentals/code-examples/ReplicaSetConfigs.cs +++ b/source/includes/fundamentals/code-examples/ReplicaSetConfigs.cs @@ -62,5 +62,13 @@ public static void Main(string[] args) var mongoClient = new MongoClient(mongoClientSettings); // end-retry-reads-writes } + + { + // start-retry-reads-writes-connection-string + var connectionString = "mongodb://localhost:27017/?retryReads=false&retryWrites=false"; + var mongoClientSettings = MongoClientSettings.FromConnectionString(connectionString); + var mongoClient = new MongoClient(mongoClientSettings); + // end-retry-reads-writes-connection-string + } } } \ No newline at end of file From c0ec14da556dac9f716545b8ac92a811b6ccf60c Mon Sep 17 00:00:00 2001 From: Michael Morisi Date: Wed, 16 Apr 2025 09:25:25 -0400 Subject: [PATCH 4/4] Fix --- source/crud/configure.txt | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/source/crud/configure.txt b/source/crud/configure.txt index 675a0e32..bcaa7ddc 100644 --- a/source/crud/configure.txt +++ b/source/crud/configure.txt @@ -206,13 +206,6 @@ The following example disables retryable reads and writes for a client. Select the :guilabel:`MongoClientSettings` or :guilabel:`Connection String` tab to see the corresponding code. -.. literalinclude:: /includes/fundamentals/code-examples/ReplicaSetConfigs.cs - :start-after: start-retry-reads-writes - :end-before: end-retry-reads-writes - :emphasize-lines: 2-3 - :language: csharp - :dedent: - .. tabs:: .. tab:: MongoClientSettings @@ -229,8 +222,8 @@ tab to see the corresponding code. :tabid: connectionstring .. literalinclude:: /includes/fundamentals/code-examples/ReplicaSetConfigs.cs - :start-after: start-retry-reads-writes - :end-before: end-retry-reads-writes + :start-after: start-retry-reads-writes-connection-string + :end-before: end-retry-reads-writes-connection-string :emphasize-lines: 1 :language: csharp :dedent: