MongoDB 3.2 – Could not find host matching read preference

MongoDB 3.2 – Could not find host matching read preference.

Environment:

  • MongoDB 3.2, WiredTiger
  • 2 shards
  • 3 node replica set

Error Message

mongos> db.collection.find()
Error: error: {
 "ok" : 0,
 "errmsg" : "could not find host matching read preference { mode: \"primary\", tags: [ {} ] } for set rs0",
 "code" : 133
}

The above error means that the query, after being routed through mongos[mongos caches config server shards information], was unable to find data from the shards to satisfy the query. 

This means there’s several possibilities why the error occurs:

  1. The metadata information in the config collections (stored in config server) is incorrect. This could mean you have the wrong IP address, wrong replica set names and etc.. Check the documents in the chunks, tags or shards collections
  2. The primary replica set in down and the automatic failover did not kick in for some reasons. Also, your read preference is set to primary and thus, there was not primary node to satify your query.

Solutions:

  1. Verify the metadata in your config database and use relevant MongoDB commands to rectify any mis-configurations. (DO NOT MODIFY MANUALLY THIS UNLESS ABSOLUTELY CONFIDENT!!)
  2. Veriy that your primary replica set is up or change your readPreference to a value that is not “primary”

Thanks!

Regards,
Wei Shan

Advertisements
  1. Leave a comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: