在mongodb中找不到主机匹配的读取首选项

时间:2016-08-24 07:33:15

标签: mongodb

我正在分片环境的新数据库中创建一个新集合。

我在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" }

2 个答案:

答案 0 :(得分:3)

看起来Read Preference正在制造问题。

请通过阅读偏好设置并设置哪个更适合您的应用

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

如果您的问题与下面jira中提到的问题有关,那么我们需要mongo版本3.3.11,目前我们只有3.2.9 released

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

答案 1 :(得分:0)

在您的情况下,只读首选项成员可能在副本集中不可用,即主数据库不可用。

出于一个或多个原因。

  • 当newely初级是越来越当选故障转移的情况。
  • 大多数服务器不可用,没有主要服务器可用。

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