mongo查询抛出的这个异常,各位大侠知道是啥原因吗

发布于 2021-11-29 21:54:17 字数 1008 浏览 806 评论 7

软件版本: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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(7

悲喜皆因你 2021-12-01 22:15:03

非常感谢Karblue,你的答复总算让我找到点头绪

不乱于心 2021-12-01 22:15:00

但不知道如何下手,我们的mongo是两台分片,难道并发量大,就出现连不上的情况,目前这种错只是偶尔出现

猫性小仙女 2021-12-01 22:14:54

回复
看看网络原因呢。表象上就是无法连上primary服务器了。为什么连不上原因就太多了。。

醉酒的小男人 2021-12-01 22:14:51

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/

成熟的代价 2021-12-01 21:05:55

貌似是无法连接mongodb 的primary主服务器。

岁吢 2021-12-01 15:01:11

1

筱果果 2021-12-01 10:40:38

自己顶下

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文