chopra
chopra

Reputation: 91

could not find host matching read preferences in mongodb

I am creating a new collection in a new database on the sharded environment.

I am getting the following error while coll.insertMany(list).

Exception in thread "main" com.mongodb.MongoCommandException: 
Command failed with error 133: 'unable to target write op for collection dbname.collection:: caused by :: 
FailedToSatisfyReadPreference: Could not confirm non-existence of database "dbname" due to inability to query the config server primary :: caused by :: 
FailedToSatisfyReadPreference: could not find host matching read preference { mode: "primary" } for set csReplSet' on server ip:27017. 
The full response is { "ok" : 0, "code" : 133, "errmsg" : "unable to target write op for collection dbname.collection:: caused by :: 
FailedToSatisfyReadPreference: Could not confirm non-existence of database \"dbname\" due to inability to query the config server primary :: caused by :: 
FailedToSatisfyReadPreference: could not find host matching read preference { mode: \"primary\" } for set csReplSet" }

Upvotes: 3

Views: 18127

Answers (2)

Arun Pratap Singh
Arun Pratap Singh

Reputation: 3646

There is possibility of read preference member is not available in replicaset in your case i.e primary not available.

For one or more reason's.

  • Failover scenario when newely primary is getting elected.
  • Majority of server's not available leaving no primary available.

https://docs.mongodb.com/manual/tutorial/troubleshoot-sharded-clusters/

Upvotes: 0

Clement Amarnath
Clement Amarnath

Reputation: 5466

It looks like Read Preference is creating problem in your end.

Please go thru read preference and set which is more appropriate for your application

https://docs.mongodb.com/manual/reference/read-preference/

If your issue is something related to the one which is mentioned in below jira then we need mongo version 3.3.11 and currently we have only 3.2.9 released.

https://jira.mongodb.org/browse/SERVER-22620

Upvotes: 4

Related Questions