Skip to content

Commit cf2870d

Browse files
authored
DOCSP-51889-retryable-reads-and-writes (#126)
* add retryable section * mb feedback
1 parent e7771df commit cf2870d

File tree

2 files changed

+56
-3
lines changed

2 files changed

+56
-3
lines changed

source/crud/configure.txt

Lines changed: 39 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -307,24 +307,60 @@ tab to see corresponding code for each approach:
307307
:tabid: settings
308308

309309
.. literalinclude:: /includes/configure-crud.kt
310-
:language: rust
310+
:language: kotlin
311311
:dedent:
312312
:start-after: start-local-threshold-settings
313313
:end-before: end-local-threshold-settings
314314

315-
316315
.. tab:: Connection URI
317316
:tabid: uri
318317

319318
.. literalinclude:: /includes/configure-crud.kt
320-
:language: rust
319+
:language: kotlin
321320
:dedent:
322321
:start-after: start-local-threshold-uri
323322
:end-before: end-local-threshold-uri
324323

325324
In the preceding example, the {+driver-short+} distributes reads among matching members
326325
within 35 milliseconds of the closest member's ping time.
327326

327+
Retryable Reads and Writes
328+
--------------------------
329+
330+
The {+driver-short+} automatically retries certain read and write operations a single time
331+
if they fail due to a network or server error.
332+
333+
You can explicitly disable retryable reads or retryable writes by setting the ``retryReads`` or
334+
``retryWrites`` option to ``false`` in a ``MongoClientSettings`` instance. You can also
335+
set the ``retryReads`` or ``retryWrites`` options in your connection URI.
336+
337+
The following example sets both retryable reads and retryable writes to ``false``. Select the :guilabel:`MongoClientSettings` or :guilabel:`Connection URI`
338+
tab to see corresponding code for each approach:
339+
340+
.. tabs::
341+
342+
.. tab:: MongoClientSettings
343+
:tabid: settings
344+
345+
.. literalinclude:: /includes/configure-crud.kt
346+
:language: kotlin
347+
:dedent:
348+
:start-after: start-retryable-reads-writes
349+
:end-before: end-retryable-reads-writes
350+
351+
.. tab:: Connection URI
352+
:tabid: uri
353+
354+
.. literalinclude:: /includes/configure-crud.kt
355+
:language: kotlin
356+
:dedent:
357+
:start-after: start-retryable-reads-writes-uri
358+
:end-before: end-retryable-reads-writes-uri
359+
360+
To learn more about supported retryable read operations, see :manual:`Retryable Reads </core/retryable-reads/>`
361+
in the {+mdb-server+} manual. To learn more about supported retryable write
362+
operations, see :manual:`Retryable Writes </core/retryable-writes/>` in the {+mdb-server+} manual.
363+
328364
API Documentation
329365
-----------------
330366

source/includes/configure-crud.kt

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,23 @@ fun main() {
106106
val latencyClient2 = MongoClient.create(latencySettings)
107107
// end-local-threshold-settings
108108

109+
// Disable retryable reads and writes using MongoClientSettings builder
110+
// start-retryable-reads-writes
111+
val retrySettings = MongoClientSettings.builder()
112+
.applyConnectionString(ConnectionString("mongodb://localhost:27017/"))
113+
.retryReads(false) // Disables automatic retries of read operations
114+
.retryWrites(false) // Disables automatic retries of write operations
115+
.build()
116+
117+
val retryClient = MongoClient.create(retrySettings)
118+
119+
// end-retryable-reads-writes
120+
121+
// start-retryable-reads-writes-uri
122+
val retryUri = "mongodb://localhost:27017/?retryReads=false&retryWrites=false"
123+
val retryUriClient = MongoClient.create(retryUri)
124+
// end-retryable-reads-writes-uri
125+
109126
// Close the MongoClient connection
110127
mongoClient.close()
111128
}

0 commit comments

Comments
 (0)