Skip to content

Commit

Permalink
修复创建mongodb原生连接时的错误 (hhyo#1291)
Browse files Browse the repository at this point in the history
  • Loading branch information
weideguo committed Dec 22, 2021
1 parent e5e777b commit 70bf9b6
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions sql/engines/mongo.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down

0 comments on commit 70bf9b6

Please sign in to comment.