Skip to content

Commit a029054

Browse files
committed
update docstring.
1 parent afd7912 commit a029054

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

django_mongodb/compiler.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -399,7 +399,8 @@ def build_query(self, columns=None):
399399
)
400400
query.combinator_pipeline = self.get_combinator_queries()
401401
else:
402-
# If we query distinct
402+
# If query is distinct, build a $group stage for distinct fields,
403+
# then set project fields based on grouped _id
403404
if self.query.distinct:
404405
distinct_fields = self.get_project_fields(
405406
columns, ordering_fields, force_expression=True
@@ -409,6 +410,7 @@ def build_query(self, columns=None):
409410
query.aggregation_pipeline.append({"$group": {"_id": distinct_fields}})
410411
query.project_fields = {key: f"$_id.{key}" for key in distinct_fields}
411412
else:
413+
# Otherwise, simply project fields without grouping
412414
query.project_fields = self.get_project_fields(columns, ordering_fields)
413415
# If columns is None, then get_project_fields() won't add
414416
# ordering_fields to $project. Use $addFields (extra_fields) instead.

0 commit comments

Comments
 (0)