Skip to content

Commit d5659e5

Browse files
committed
DOCSP-49095: Retryable Reads and Writes
1 parent 3f2c2ae commit d5659e5

File tree

2 files changed

+32
-3
lines changed

2 files changed

+32
-3
lines changed

source/crud/configure.txt

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,26 @@ The following example sets the read preference to ``ReadPreference.Secondary`` f
191191
For more information about read preference, see :manual:`Read Preference
192192
</core/read-preference/>` in the {+mdb-server+} manual.
193193

194+
Retryable Reads and Writes
195+
--------------------------
196+
197+
The {+driver-short+} automatically retries certain read and write operations a single time
198+
if they fail due to a network or server error.
199+
200+
You can explicitly disable retryable reads or retryable writes by setting the ``RetryReads``
201+
or ``RetryWrites`` options on a ``MongoClientSettings`` object and passing this object to the
202+
``MongoClient`` constructor. The following example disables retryable reads and writes for
203+
a client:
204+
205+
.. literalinclude:: /includes/fundamentals/code-examples/ReplicaSetConfigs.cs
206+
:start-after: start-retry-reads-writes
207+
:end-before: end-retry-reads-writes
208+
:language: csharp
209+
:dedent:
210+
211+
To learn more about supported retryable reads and retryable writes, see :manual:`Retryable Reads </core/retryable-reads/>`
212+
and :manual:`Retryable Writes </core/retryable-writes/>` in the {+mdb-server+} manual.
213+
194214
API Documentation
195215
-----------------
196216

source/includes/fundamentals/code-examples/ReplicaSetConfigs.cs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ public static void Main(string[] args)
88
var client = new MongoClient("mongodb://localhost:27017");
99
{
1010
// start-write-concern-client
11-
var mongoClientSettings = MongoClientSettings.FromConnectionString("<connection string URI>");
11+
var mongoClientSettings = MongoClientSettings.FromConnectionString("<connection URI>");
1212
mongoClientSettings.WriteConcern = WriteConcern.WMajority;
1313
var mongoClient = new MongoClient(mongoClientSettings);
1414
// end-write-concern-client
@@ -24,7 +24,7 @@ public static void Main(string[] args)
2424

2525
{
2626
// start-read-concern-client
27-
var mongoClientSettings = MongoClientSettings.FromConnectionString("<connection string URI>");
27+
var mongoClientSettings = MongoClientSettings.FromConnectionString("<connection URI>");
2828
mongoClientSettings.ReadConcern = ReadConcern.Majority;
2929
var mongoClient = new MongoClient(mongoClientSettings);
3030
// end-read-concern-client
@@ -40,7 +40,7 @@ public static void Main(string[] args)
4040

4141
{
4242
// start-read-preference-client
43-
var mongoClientSettings = MongoClientSettings.FromConnectionString("<connection string URI>");
43+
var mongoClientSettings = MongoClientSettings.FromConnectionString("<connection URI>");
4444
mongoClientSettings.ReadPreference = ReadPreference.Secondary;
4545
var mongoClient = new MongoClient(mongoClientSettings);
4646
// end-read-preference-client
@@ -53,5 +53,14 @@ public static void Main(string[] args)
5353
.WithReadPreference(ReadPreference.Secondary);
5454
// end-read-preference-collection
5555
}
56+
57+
{
58+
// start-retry-reads-writes
59+
var mongoClientSettings = MongoClientSettings.FromConnectionString("<connection URI>");
60+
mongoClientSettings.RetryReads = false;
61+
mongoClientSettings.RetryWrites = false;
62+
var mongoClient = new MongoClient(mongoClientSettings);
63+
// end-retry-reads-writes
64+
}
5665
}
5766
}

0 commit comments

Comments
 (0)