diff --git a/source/crud/configure.txt b/source/crud/configure.txt index 01ea55ed..bcaa7ddc 100644 --- a/source/crud/configure.txt +++ b/source/crud/configure.txt @@ -191,6 +191,47 @@ 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. 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. + +.. 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-connection-string + :end-before: end-retry-reads-writes-connection-string + :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. + API Documentation ----------------- diff --git a/source/includes/fundamentals/code-examples/ReplicaSetConfigs.cs b/source/includes/fundamentals/code-examples/ReplicaSetConfigs.cs index fcb35edd..cf7c2163 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,22 @@ 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 + } + + { + // 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