MongoServerSelectionError: Could not find host matching read preference { mode: "secondary" } for set rs0
The requested read preference (secondary, nearest with tags) matches no available member.
Could not find host matching read preference { mode: "secondary" } for set rs0MongoServerSelectionError: Could not find host matching read preferenceNo suitable servers found: `serverSelectionTimeoutMS` expiredCould not find host matching read preference with tags Meaning
With secondary read preference and no healthy secondaries (or tags that don't match) selection fails. Use secondaryPreferred for graceful fallback, check rs.status(), tag sets and maxStalenessSeconds, and hidden/delayed members.
Common causes
- readPreference=secondary but no secondary available
- Tag sets don't match any member
- maxStalenessSeconds excludes lagging members
- Secondaries down or recovering
- Replica set with only primary
⚡ Quick fix
- Use
secondaryPreferred - Check member health with
rs.status() - Review tags/maxStaleness settings
Detailed fix by platform
mongosh
rs.status().members.map(m => ({name: m.name, state: m.stateStr, lag: m.optimeDate}))
How to diagnose
- Preference — secondary vs preferred?
- Members — Healthy secondaries?
- Tags — Match?
🔧 Still not fixed?
Many errors look alike. If the steps above didn’t solve it, one of these is probably what you’re facing:
Similar errors
- AlreadyInitialized: already initialized MongoServerError: already initialized (rs.initiate on a configured replica set)
- No primary found in replica set / ReplicaSetNoPrimary MongoServerSelectionError: Server selection timed out after 30000 ms — topology type ReplicaSetNoPrimary
- NotWritablePrimary: not primary and secondaryOk=false MongoServerError: not primary and secondaryOk=false / NotWritablePrimary: not master
Most viewed in MongoDB
- Document failed validation MongoDB: MongoServerError: Document failed validation (code 121)
- MongoParseError MongoDB: MongoParseError: Invalid scheme, expected connection string to start with "mongodb://" or "mongodb+srv://"
- bad auth : Authentication failed MongoDB: MongoServerError: bad auth : Authentication failed (code 8000 / 18)
Other ways to find it
Where this error sits
Origin: Data. Errors that are often confused with or caused by this one (click to open):
🧠 Still stuck? Analyze your error
Paste the full message, response headers or stack trace — we'll detect the platform and point to the most likely cause.
💬 What worked for others
No tips yet — did something else fix this for you?
Share what worked for you
Tips are checked by an editor before they appear. Links are removed.
Report a correction or suggest an improvement
Last updated 5 Nov 2026