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

mongdb查询的结果集中缺少字段 #1192

Merged
merged 1 commit into from
Oct 17, 2021
Merged

mongdb查询的结果集中缺少字段 #1192

merged 1 commit into from
Oct 17, 2021

Conversation

cpzt
Copy link
Contributor

@cpzt cpzt commented Oct 14, 2021

MongoEngine.get_all_columns_by_tb只取了第一行和最后一行数据的字段名,查询的结果集中可能存在其他的字段,因此需要加上这些字段

@@ -825,6 +825,8 @@ def parse_tuple(self, cursor, db_name, tb_name, projection=None):
result = self.get_all_columns_by_tb(db_name=db_name, tb_name=tb_name)
columns = result.rows
columns.insert(0, "mongodballdata") # 隐藏JSON结果列
columns = self.fill_query_columns(cursor, columns)

Copy link
Owner

Choose a reason for hiding this comment

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

这里应该遗漏了前面insert的mongodballdata

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fill_query_columns方法会解析出cursor(查询结果)中所有包含的字段,检查是否在columns中,如果不在就添加至columns。所以不会遗漏mongodballdata字段

Copy link
Owner

Choose a reason for hiding this comment

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

mongodballdata是为了前台展示json增加的虚拟列,不存在于查询结果中

Copy link
Contributor Author

@cpzt cpzt Oct 17, 2021

Choose a reason for hiding this comment

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

fill_query_columns方法只会往columns添加字段,不会影响原来的columns(mongodballdata还在columns中);可以看一下测试用例test_fill_query_columns

Copy link
Owner

Choose a reason for hiding this comment

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

抱歉,看到变量重新赋值,没注意到

@hhyo hhyo merged commit ae58fbd into hhyo:master Oct 17, 2021
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.

None yet

2 participants