We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
mongodb的查询尾部存在分号或者前后存在空格时处理错误,以及点击执行计划时处理错误。 注意到有一个pr( #1198 ),但感觉处理得不够优雅
执行计划
补丁 mongo.py.20211126.patch
diff --git a/sql/engines/mongo.py b/sql/engines/mongo.py index 86e7c99..460ee96 100644 --- a/sql/engines/mongo.py +++ b/sql/engines/mongo.py @@ -698,12 +698,13 @@ class MongoEngine(EngineBase): def query_check(self, db_name=None, sql=''): """提交查询前的检查""" - + sql = sql.strip() if sql.startswith("explain"): sql = sql.replace("explain", "") + ".explain()" + sql = re.sub("[;\s]*.explain\(\)", ".explain()", sql).strip() result = {'msg': '', 'bad_query': False, 'filtered_sql': sql, 'has_star': False} pattern = re.compile( - r'''^db\.(\w+\.?)+(?:\([\s\S]*\)$)|^db\.getCollection\((?:\s*)(?:'|")(\w+\.?)+('|")(\s*)\)\.([A-Za-z]+)(\([\s\S]*\)$)''') + r'''^db\.(\w+\.?)+(?:\([\s\S]*\)(\s*;*)$)|^db\.getCollection\((?:\s*)(?:'|")(\w+\.?)+('|")(\s*)\)\.([A-Za-z]+)(\([\s\S]*\)(\s*;*)$)''') m = pattern.match(sql) if m is not None: logger.debug(sql)
应用补丁 patch -p1 < mongo.py.20211126.patch
The text was updated successfully, but these errors were encountered:
sql = sql[7:]+".explain()" re.sub("[;\s]*.explain\(\)$", ".explain()", sql).strip()
防止查询中存在explain字符串时出现错误,如explain db.a.find({"a":"explain()"})
explain
explain db.a.find({"a":"explain()"})
Sorry, something went wrong.
代码优化可以提pr沟通,感谢贡献
mongodb查询优化 (hhyo#1252)
f115b03
Merge pull request #1253 from weideguo/master
b1d48cf
mongodb查询优化 (#1252)
No branches or pull requests
目前遇到的问题/使用障碍
mongodb的查询尾部存在分号或者前后存在空格时处理错误,以及点击
执行计划
时处理错误。注意到有一个pr( #1198 ),但感觉处理得不够优雅
希望如何解决/实现它
补丁 mongo.py.20211126.patch
应用补丁
patch -p1 < mongo.py.20211126.patch
The text was updated successfully, but these errors were encountered: