Skip to content

Commit 3b8b13b

Browse files
committed
Add AggregateFilter, StringgAgg.as_mql() as per
django/django@4b977a5
1 parent 469c265 commit 3b8b13b

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

django_mongodb_backend/aggregates.py

+20-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
1-
from django.db.models.aggregates import Aggregate, Count, StdDev, Variance
1+
from django.db.models.aggregates import (
2+
Aggregate,
3+
AggregateFilter,
4+
Count,
5+
StdDev,
6+
StringAgg,
7+
Variance,
8+
)
29
from django.db.models.expressions import Case, Value, When
310
from django.db.models.lookups import IsNull
411

@@ -31,6 +38,10 @@ def aggregate(
3138
return {f"${operator}": lhs_mql}
3239

3340

41+
def aggregate_filter(self, compiler, connection, **extra_context):
42+
return self.condition.as_mql(compiler, connection, **extra_context)
43+
44+
3445
def count(self, compiler, connection, resolve_inner_expression=False, **extra_context): # noqa: ARG001
3546
"""
3647
When resolve_inner_expression=True, return the MQL that resolves as a
@@ -72,8 +83,16 @@ def stddev_variance(self, compiler, connection, **extra_context):
7283
return aggregate(self, compiler, connection, operator=operator, **extra_context)
7384

7485

86+
def string_agg(self, compiler, connection, **extra_context): # # noqa: ARG001
87+
from django.db import NotSupportedError
88+
89+
raise NotSupportedError("StringAgg is not supported.")
90+
91+
7592
def register_aggregates():
7693
Aggregate.as_mql = aggregate
94+
AggregateFilter.as_mql = aggregate_filter
7795
Count.as_mql = count
7896
StdDev.as_mql = stddev_variance
97+
StringAgg.as_mql = string_agg
7998
Variance.as_mql = stddev_variance

0 commit comments

Comments
 (0)