From 3ebcb1c7f385424174bd100f84a852269e1f23af Mon Sep 17 00:00:00 2001 From: mahdihaghverdi Date: Mon, 30 Oct 2023 23:15:26 +0330 Subject: [PATCH] fix the wrong output query Signed-off-by: mahdihaghverdi --- aggify/aggify.py | 16 +++++++--------- tests/test_query.py | 3 ++- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/aggify/aggify.py b/aggify/aggify.py index 5631b12..35fa41b 100644 --- a/aggify/aggify.py +++ b/aggify/aggify.py @@ -203,17 +203,15 @@ def __to_aggregate(self, query: dict[str, Any]) -> None: if match != {}: matches.append(match) - self.pipelines.extend( - [ - self.__lookup( - from_collection=from_collection._meta["collection"], # noqa - local_field=local_field, - as_name=as_name, - ), - *[{"$match": match} for match in matches], - ] + self.pipelines.append( + self.__lookup( + from_collection=from_collection._meta["collection"], # noqa + local_field=local_field, + as_name=as_name, + ) ) self.unwind(as_name) + self.pipelines.extend([{"$match": match} for match in matches]) @last_out_stage_check def __getitem__(self, index: slice | int) -> "Aggify": diff --git a/tests/test_query.py b/tests/test_query.py index c09a42f..c8e21e1 100644 --- a/tests/test_query.py +++ b/tests/test_query.py @@ -70,8 +70,9 @@ class ParameterTestCase: "localField": "owner_id", } }, - {"$match": {"owner.deleted_at": None}}, {"$unwind": "$owner"}, + {"$match": {"owner.deleted_at": None}}, + ], ), ParameterTestCase(