Skip to content

Commit

Permalink
fixed mongo connect error
Browse files Browse the repository at this point in the history
  • Loading branch information
quanbisen committed Aug 16, 2024
1 parent e1fc3f6 commit 4975393
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 4975393

Please sign in to comment.