From 70bf9b6d31a7a5064eaaa5351776f49586fb55d6 Mon Sep 17 00:00:00 2001 From: weideguo <2515717245@qq.com> Date: Wed, 22 Dec 2021 16:48:35 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=88=9B=E5=BB=BAmongodb?= =?UTF-8?q?=E5=8E=9F=E7=94=9F=E8=BF=9E=E6=8E=A5=E6=97=B6=E7=9A=84=E9=94=99?= =?UTF-8?q?=E8=AF=AF=20(hhyo#1291)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sql/engines/mongo.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/sql/engines/mongo.py b/sql/engines/mongo.py index 9de05f890e..19319e1cea 100644 --- a/sql/engines/mongo.py +++ b/sql/engines/mongo.py @@ -503,11 +503,12 @@ def execute_check(self, db_name=None, sql=''): return check_result def get_connection(self, db_name=None): - self.db_name = db_name or self.instance.db_name - self.conn = pymongo.MongoClient(self.host, self.port, authSource=self.db_name, connect=True, + self.db_name = db_name or self.instance.db_name or 'admin' + auth_db = self.instance.db_name or 'admin' + self.conn = pymongo.MongoClient(self.host, self.port, authSource=auth_db, connect=True, connectTimeoutMS=10000) if self.user and self.password: - self.conn[self.db_name].authenticate(self.user, self.password, self.db_name) + self.conn[self.db_name].authenticate(self.user, self.password, auth_db) return self.conn def close(self):