Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pymongo4.x支持mongodb3.6低版本 #2645

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 7 additions & 8 deletions sql/engines/mongo.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from dateutil.parser import parse
from bson.objectid import ObjectId
from bson.int64 import Int64
from urllib.parse import quote_plus

from . import EngineBase
from .models import ResultSet, ReviewSet, ReviewResult
Expand Down Expand Up @@ -795,15 +796,13 @@ 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:
LeoQuote marked this conversation as resolved.
Show resolved Hide resolved
self.conn[self.db_name].authenticate(self.user, self.password, auth_db)
self.user = quote_plus(self.user)
self.password = quote_plus(self.password)
LeoQuote marked this conversation as resolved.
Show resolved Hide resolved
uri = f"mongodb://{self.user}:{self.password}@{self.host}:{self.port}/{self.db_name}?authSource={auth_db}"
else:
uri = f"mongodb://{self.host}:{self.port}/{self.db_name}"
self.conn = pymongo.MongoClient(uri, connect=True, connectTimeoutMS=10000)
return self.conn

def close(self):
Expand Down
Loading