Skip to content

Commit 0bda9cd

Browse files
committed
Add subqueries in group stage.
1 parent b33bc80 commit 0bda9cd

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

django_mongodb/compiler.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -254,15 +254,15 @@ def pre_sql_setup(self, with_col_aliases=False):
254254
all_replacements.update(replacements)
255255
pipeline = self._build_aggregation_pipeline(ids, group)
256256
if self.having:
257-
pipeline.append(
258-
{
259-
"$match": {
260-
"$expr": self.having.replace_expressions(all_replacements).as_mql(
261-
self, self.connection
262-
)
263-
}
264-
}
257+
having = self.having.replace_expressions(all_replacements).as_mql(
258+
self, self.connection
265259
)
260+
# Add having subqueries.
261+
for query in self.subqueries or ():
262+
pipeline.extend(query.get_pipeline())
263+
# Clean added subqueries.
264+
self.subqueries = None
265+
pipeline.append({"$match": {"$expr": having}})
266266
self.aggregation_pipeline = pipeline
267267
self.annotations = {
268268
target: expr.replace_expressions(all_replacements)

0 commit comments

Comments
 (0)