Docs Menu
Docs Home
/ / /
Go Driver
/

Configure CRUD Operations

The Go driver 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 when creating a new client by using the options.Client struct.

The following example disables retryable reads and writes for a client by using the ClientOptions setter functions:

// Defines the client options
clientOps := options.Client().
ApplyURI(uri).
SetRetryWrites(false).
SetRetryReads(false)
// Creates a new client using the specified options
client, err := mongo.Connect(clientOps)
if err != nil {
panic(err)
}

To learn more about supported retryable read operations, see Retryable Reads in the MongoDB Server manual. To learn more about supported retryable write operations, see Retryable Writes in the MongoDB Server manual.

Back

Compound Operations

On this page