问题 处理此类错误的最佳方法是什么?说后重试,最多 30 秒。 5次?
设置
我在 AWS ECS 上有一个 PRIMARY + 两个 SECONDARY 设置,并且没有一个盒子被关闭。
从异常消息中,Mongo 似乎在说“我没有 PRIMARY,我试图从 SECONDARY 获取数据,但它们也已关闭”。但是,没有一个 Mongo 服务器停机。我有另一个进程正在运行,它有一个默认的 read_preference
SECONDARY
并且运行良好。
异常
is_auth = db.authenticate("myid","mypass")
File "/usr/local/lib/python2.7/dist-packages/pymongo/database.py", line
720, in authenticate
read_preference=read_pref)["nonce"]
File "/usr/local/lib/python2.7/dist-packages/pymongo/database.py", line
390, in command
result = self["$cmd"].find_one(command, **extra_opts)
File "/usr/local/lib/python2.7/dist-packages/pymongo/collection.py",
line 598, in find_one
for result in self.find(spec_or_id, *args, **kwargs).limit(-1):
File "/usr/local/lib/python2.7/dist-packages/pymongo/cursor.py", line
814, in next
if len(self.__data) or self._refresh():
File "/usr/local/lib/python2.7/dist-packages/pymongo/cursor.py", line
763, in _refresh
self.__uuid_subtype))
File "/usr/local/lib/python2.7/dist-packages/pymongo/cursor.py", line
700, in __send_message
**kwargs)
File
"/usr/local/lib/python2.7/dist-packages/pymongo/mongo_replica_set_client.py
", line 1210, in _send_message_with_response
raise AutoReconnect(msg, errors)
AutoReconnect: No replica set members available for query with
ReadPreference PRIMARY_PREFERRED
代码
connection = MongoReplicaSetClient(, replicaSet='myReplica-2', use_greenlets = True)
db = "my_real_db"
db.read_preference = ReadPreference.PRIMARY
is_auth = db.authenticate("myid", "mypass") # ERROR at this line
版本
MongoDB:2.2.0 和 PyMongo:2.4.2
最佳答案
检查您的 connectTimeoutMS
和 socketTimeoutMS
。可能是,它很小?
关于mongodb - 自动重连 : No replica set members available for query with ReadPreference PRIMARY_PREFERRED,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/16901238/