- • Add retryWrites=true to your connection string
- • Disable try-once behaviour (serverSelectionTryOnce=false)
- • Tune serverSelectionTimeoutMS closer to expected election time (e.g. 15 seconds)
Use the driver as you would normally:
- • Multi-document writes (e.g. updateMany) may still fail; you’re no worse off
- • Single-document writes may still fail after one retry attemp
Drivers will default to retryWrites=true with MongoDBÂ 4.2