Could not find host matching read preference MongoDB Origin: Data OSI layer 7 · Application Last updated 5 Nov 2026

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.

Exact message you may see 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
Seen on: MongoDB

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

  1. Use secondaryPreferred
  2. Check member health with rs.status()
  3. Review tags/maxStaleness settings

Detailed fix by platform

mongosh

  1. rs.status().members.map(m => ({name: m.name, state: m.stateStr, lag: m.optimeDate}))

How to diagnose

  1. Preference — secondary vs preferred?
  2. Members — Healthy secondaries?
  3. 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:

Where this error sits

Origin: Data. Errors that are often confused with or caused by this one (click to open):

AlreadyInitialized: already initialized — MongoServerError: already initialized (rs.initiate on a configured replica set) (MongoDB)AlreadyInitialized: a…No primary found in replica set / ReplicaSetNoPrimary — MongoServerSelectionError: Server selection timed out after 30000 ms — topology type ReplicaSetNoPrimary (MongoDB)No primary found in r…NotWritablePrimary: not primary and secondaryOk=false — MongoServerError: not primary and secondaryOk=false / NotWritablePrimary: not master (MongoDB)NotWritablePrimary: n…rs.initiate failed: member not reachable / no host described in new configuration — MongoDB: replSetInitiate quorum check failed: Could not connect to mongo2:27017 / No host described in new configuration 1 for replica set rs0 maps to this node (MongoDB)rs.initiate failed: m…Secondary too stale to catch up (RECOVERING) — MongoDB: We are too stale to use X as a sync source / replSet too stale to catch up — member in RECOVERING state (MongoDB)Secondary too stale t…Sort/Group exceeded memory limit of 100 MB (allowDiskUse) — MongoServerError: Exceeded memory limit for $group, but didn't allow external sort. Pass allowDiskUse:true to opt in (MongoDB)Sort/Group exceeded m…Transaction numbers are only allowed on a replica set member or mongos — MongoServerError: Transaction numbers are only allowed on a replica set member or mongos (MongoDB)Transaction numbers a…Could not…

Explore the map of this error Full error map →

🧠 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.