From e38d3f7ffb976d60401ffb1eb95f4046af29032a Mon Sep 17 00:00:00 2001 From: root Date: Tue, 20 Sep 2022 09:57:45 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E4=BA=91mongodb=E4=B8=8D?= =?UTF-8?q?=E8=83=BD=E5=88=9B=E5=BB=BA=E7=B4=A2=E5=BC=95=E7=9A=84bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sql/engines/mongo.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/sql/engines/mongo.py b/sql/engines/mongo.py index d1733b071b..4d0b3e509b 100644 --- a/sql/engines/mongo.py +++ b/sql/engines/mongo.py @@ -378,6 +378,11 @@ def get_slave(self): sql = """var host=""; rs.status().members.forEach(function(item) {i=1; if (item.stateStr =="SECONDARY") \ {host=item.name } }); print(host);""" slave_msg = self.exec_cmd(sql) + # 如果是阿里云的云mongodb,会获取不到备节点真实的ip和端口,那就干脆不获取,直接用主节点来执行sql + # 如果是自建mongodb,获取到备节点的ip是192.168.1.33:27019这样的值;但如果是阿里云mongodb,获取到的备节点ip是SECONDARY、hiddenNode这样的值 + # 所以,为了使代码更加通用,通过有无冒号来判断自建Mongod还是阿里云mongdb;没有冒号就判定为阿里云mongodb,直接返回false; + if ":" not in slave_msg: + return False if slave_msg.lower().find("undefined") < 0: sp_host = slave_msg.replace('"', "").split(":") self.host = sp_host[0]