# retryWrites, write concern, read preference

```text
mongodb+srv://cluster0.abc123.mongodb.net/mydb?retryWrites=true&w=majority
```

(credentials go in the user-info part of the real string; shown without them here)

## What each does

- `retryWrites=true`: the driver retries a write once after a transient network error. Required for multi-document transactions; without it, transactions fail outright. Modern drivers default it to true, but set it explicitly so a hand-built string is never wrong.
- `w=majority`: the write is acknowledged after a majority of replica set members have it. This is the durability you want for anything that matters. `w=1` is faster and less safe; know which you chose.
- `readPreference=primary` (the default): reads go to the primary. Transactions require it. Change it to `secondary` or `nearest` only for analytics-style reads that tolerate staleness, and never inside a transaction.

## Rules

- Keep `retryWrites=true` on every Atlas connection string. There is no good reason to turn it off against Atlas.
- Retryable writes cover single writes. Multi-document transactions need their own retry loop for `TransientTransactionError` and `UnknownTransactionCommitResult`; the driver does not do that for you.
- Do not set read preference to secondary to "reduce primary load" for operational writes. You will read stale data and break transactions.

## Verify

Run a multi-document transaction against the cluster. If it succeeds, retryWrites and read preference are correct.