File tree Expand file tree Collapse file tree 1 file changed +3
-1
lines changed Expand file tree Collapse file tree 1 file changed +3
-1
lines changed Original file line number Diff line number Diff 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.
You can’t perform that action at this time.
0 commit comments