mongo查询抛出的这个异常,各位大侠知道是啥原因吗
软件版本:python2.7,pymongo3.2 ,MongoDB3.2
错误信息:在用find_one方法查询时 data=db.find_one({'cid':tempDict['cid']}) ,抛出如下错, 查了好久也没查出原因。。。
File "build/bdist.linux-x86_64/egg/pymongo/collection.py", line 1006, in find_one
for result in cursor.limit(-1):
File "build/bdist.linux-x86_64/egg/pymongo/cursor.py", line 1097, in next
if len(self.__data) or self._refresh():
File "build/bdist.linux-x86_64/egg/pymongo/cursor.py", line 1019, in _refresh
self.__read_concern))
File "build/bdist.linux-x86_64/egg/pymongo/cursor.py", line 905, in __send_message
helpers._check_command_response(doc['data'][0])
File "build/bdist.linux-x86_64/egg/pymongo/helpers.py", line 196, in _check_command_response
raise OperationFailure(msg % errmsg, code, response)
OperationFailure: could not find host matching read preference { mode: "primary", tags: [ {} ] } for set rs1
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
非常感谢Karblue,你的答复总算让我找到点头绪
但不知道如何下手,我们的mongo是两台分片,难道并发量大,就出现连不上的情况,目前这种错只是偶尔出现
回复
看看网络原因呢。表象上就是无法连上primary服务器了。为什么连不上原因就太多了。。
primary
All read operations use only the current replica set primary. [5] This is the default read mode. If the primary is unavailable, read operations produce an error or throw an exception.
看样子的确是这样. primary 服务器不可用。 read操作就会抛出异常。
详情见:https://docs.mongodb.org/manual/reference/read-preference/
貌似是无法连接mongodb 的primary主服务器。
自己顶下