Skip to content

Update mongo.py#2970

Open
huangsijun17 wants to merge 7 commits intohhyo:masterfrom
huangsijun17:patch-2
Open

Update mongo.py#2970
huangsijun17 wants to merge 7 commits intohhyo:masterfrom
huangsijun17:patch-2

Conversation

@huangsijun17
Copy link

@huangsijun17 huangsijun17 commented May 12, 2025

兼容高版本MongoDB Shell。

Fix: #2969

@huangsijun17
Copy link
Author

huangsijun17 commented May 12, 2025

测试脚本没装新、老版的Mongosh,能过就怪了。

Copy link
Owner

@hhyo hhyo left a comment

Choose a reason for hiding this comment

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

ci的对应的yaml也可以做调整装上客户端

common_params["auth_options"] = ""
return cmd_template.format(**common_params)

def get_mongosh(self):
Copy link
Owner

Choose a reason for hiding this comment

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

建议放在init方法内


def execute(self, db_name=None, sql=""):
"""mongo命令执行语句"""
self.get_mongosh()
Copy link
Owner

Choose a reason for hiding this comment

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

只在execute内覆盖,会导致其他方法找不到类属性报错

try:
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.

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

# 提取公共参数
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 未定义

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants