Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
7 changes: 7 additions & 0 deletions .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,5 +63,12 @@ jobs:
# make bootstrap
# make release

# Install MongoDB Shell to test the recognition of the mongo client.
- name: Install MongoDB Shell
run: |
wget https://downloads.mongodb.com/compass/mongodb-mongosh_2.5.2_amd64.deb
sudo apt install ./mongodb-mongosh_2.5.2_amd64.deb
mongosh --version

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v1
8 changes: 8 additions & 0 deletions .github/workflows/django.yml
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,14 @@ jobs:
python -m pip install --upgrade pip
pip install -r requirements.txt
pip install -r dev-requirements.txt


# Install MongoDB Shell to test the recognition of the mongo client.
- name: Install MongoDB Shell
run: |
wget https://downloads.mongodb.com/compass/mongodb-mongosh_2.5.2_amd64.deb
sudo apt install ./mongodb-mongosh_2.5.2_amd64.deb
mongosh --version

- name: Init Table
run: |
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ Django==4.1.13
mysqlclient==2.*
requests==2.31.0
simplejson==3.17.2
json5==0.12.0
mybatis_mapper2sql==0.1.9
django-auth-ldap==4.1.0
python-dateutil==2.8.1
Expand Down
20 changes: 15 additions & 5 deletions sql/engines/mongo.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# -*- coding: UTF-8 -*-
import os
import re
import time
import pymongo
Expand All @@ -8,6 +9,8 @@
import simplejson as json
import datetime
import tempfile
import json5
import shutil
from bson.son import SON
from bson import json_util
from pymongo.errors import OperationFailure
Expand All @@ -23,8 +26,12 @@

logger = logging.getLogger("default")

# mongo客户端安装在本机的位置
mongo = "mongo"
# 获取本机的mongo shell客户端
mongo = shutil.which("mongosh") or shutil.which("mongo")
if mongo:
mongo = os.path.basename(mongo)
else:
raise Exception("Mongo客户端未找到。")


# 自定义异常
Expand Down Expand Up @@ -353,7 +360,7 @@ def _build_cmd(
):
# 提取公共参数
common_params = {
"mongo": "mongo",
"mongo": self.mongo,
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

self.mongo 未定义

"host": self.host,
"port": self.port,
"db_name": db_name,
Expand Down Expand Up @@ -477,9 +484,12 @@ def execute(self, db_name=None, sql=""):
)
else:
try:
r = json.loads(r)
if self.mongo == "mongosh":
r = json5.loads(re.search(r"[{\[].*[\]}]", r).group(0))
else:
r = json.loads(r)
except Exception as e:
logger.info(str(e))
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

如果明确是版本差异,可以通过客户端版本区分

logger.warning(str(e))
finally:
methodStr = exec_sql.split(").")[-1].split("(")[0].strip()
if "." in methodStr:
Expand Down
Loading