## TL;DR

Change it to secondary or nearest only for analytics-style reads that tolerate staleness, and never inside a transaction. Run a multi-document transaction against the cluster.

## Steps

1. - `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.

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

## When to use

You are seeing this: ``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) Use this skill when you run into "MongoDB Atlas: retryWrites, write concern, and read preference that work".

## When not to use

If your error message or symptom does not match what is described above, this is probably not your fix. Search for your exact error text instead of forcing this one to fit.

## Versions

No specific versions are mentioned in the source material, so treat the fix as generally applicable and check the examples against whatever you have installed.

## Why this happens

The original report does not dig into a root cause. It documents the symptom and the fix that resolved it.
