From e8df18d14e9419b6efc3a24aadd34c06db1d15be Mon Sep 17 00:00:00 2001 From: Jongmin Kim Date: Mon, 25 Nov 2024 14:07:16 +0900 Subject: [PATCH] feat: change unwind option in analyze query Signed-off-by: Jongmin Kim --- src/spaceone/core/model/mongo_model/__init__.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/spaceone/core/model/mongo_model/__init__.py b/src/spaceone/core/model/mongo_model/__init__.py index 51d137b..e7868a9 100644 --- a/src/spaceone/core/model/mongo_model/__init__.py +++ b/src/spaceone/core/model/mongo_model/__init__.py @@ -610,12 +610,7 @@ def _stat_with_unwind( raise ERROR_DB_QUERY(reason="unwind option should have path key.") unwind_path = unwind["path"] - unwind_filter = unwind.get("filter") - - aggregate = [{"unwind": {"path": unwind_path}}] - - if unwind_filter: - aggregate.append({"match": {"filter": unwind_filter}}) + aggregate = [{"unwind": unwind}] # Add project stage project_fields = [] @@ -1088,6 +1083,11 @@ def _make_aggregate_rules(cls, aggregate): if "unwind" in stage: rule = cls._make_unwind_rule(stage["unwind"]) _aggregate_rules.append(rule) + + if unwind_filter := stage["unwind"].get("filter"): + rule = cls._make_match_rule({"filter": unwind_filter}) + _aggregate_rules.append(rule) + elif "group" in stage: rule, group_keys = cls._make_group_rule(stage["group"], _group_keys) _aggregate_rules.append(rule)