Skip to content

Commit

Permalink
fixed mongo connect error (#2760)
Browse files Browse the repository at this point in the history
Co-authored-by: quanbisen <bisen_quan@lebo.cn>
  • Loading branch information
quanbisen and quanbisen authored Aug 30, 2024
1 parent 8996542 commit 083e841
Showing 1 changed file with 18 additions and 8 deletions.
26 changes: 18 additions & 8 deletions sql/engines/mongo.py
Original file line number Diff line number Diff line change
Expand Up @@ -795,15 +795,25 @@ def execute_check(self, db_name=None, sql=""):
def get_connection(self, db_name=None):
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, auth_db)
self.conn = pymongo.MongoClient(
self.host,
self.port,
username=self.user,
password=self.password,
authSource=auth_db,
connect=True,
connectTimeoutMS=10000,
)
else:
self.conn = pymongo.MongoClient(
self.host,
self.port,
authSource=auth_db,
connect=True,
connectTimeoutMS=10000,
)
return self.conn

def close(self):
Expand Down

0 comments on commit 083e841

Please sign in to comment.