Skip to content

Commit 642dc13

Browse files
committed
add section to configure crud page
1 parent beb8820 commit 642dc13

File tree

2 files changed

+58
-0
lines changed

2 files changed

+58
-0
lines changed

source/crud/configure.txt

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,24 @@ Configure CRUD Operations
1919

2020
.. TODO
2121

22+
Retryable Reads and Writes
23+
--------------------------
24+
25+
{+driver-short+} automatically retries certain read and write operations a single time
26+
if they fail due to a network or server error.
27+
28+
You can explicitly disable retryable reads or retryable writes by setting the
29+
``retryReads`` or ``retryWrites`` option to ``False`` when creating a new client
30+
by using the ``options.Client`` struct.
31+
32+
The following example disables retryable reads and writes for a client:
33+
34+
.. literalinclude:: /includes/fundamentals/code-snippets/CRUD/retryableReadsWrites.go
35+
:start-after: start-retryable-example
36+
:end-before: end-retryable-example
37+
:language: go
38+
:dedent:
39+
40+
To learn more about supported retryable read operations, see :manual:`Retryable Reads </core/retryable-reads/>`
41+
in the {+mdb-server+} manual. To learn more about supported retryable write
42+
operations, see :manual:`Retryable Writes </core/retryable-writes/>` in the {+mdb-server+} manual.
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package main
2+
3+
import (
4+
"context"
5+
"log"
6+
"os"
7+
8+
"go.mongodb.org/mongo-driver/v2/mongo"
9+
"go.mongodb.org/mongo-driver/v2/mongo/options"
10+
)
11+
12+
func main() {
13+
var uri string
14+
if uri = os.Getenv("MONGODB_URI"); uri == "" {
15+
log.Fatal("You must set your 'MONGODB_URI' environment variable. See\n\t https://www.mongodb.com/docs/drivers/go/current/usage-examples/#environment-variable")
16+
}
17+
18+
// start-retryable-example
19+
// Defines the client options
20+
clientOps := options.Client().
21+
ApplyURI(uri).
22+
SetRetryWrites(false).
23+
SetRetryReads(false)
24+
25+
// Creates a new client and connects to the server
26+
client, err := mongo.Connect(clientOps)
27+
if err != nil {
28+
panic(err)
29+
}
30+
// end-retryable-example
31+
32+
defer func() {
33+
if err = client.Disconnect(context.TODO()); err != nil {
34+
panic(err)
35+
}
36+
}()
37+
}

0 commit comments

Comments
 (0)