Skip to content

DOCSP-51889-retryable-reads-and-writes #126

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 39 additions & 3 deletions source/crud/configure.txt
Original file line number Diff line number Diff line change
Expand Up @@ -307,24 +307,60 @@ 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

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
--------------------------

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
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 </core/retryable-reads/>`
in the {+mdb-server+} manual. To learn more about supported retryable write
operations, see :manual:`Retryable Writes </core/retryable-writes/>` in the {+mdb-server+} manual.

API Documentation
-----------------

Expand Down
17 changes: 17 additions & 0 deletions source/includes/configure-crud.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
Loading