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):
399
399
)
400
400
query .combinator_pipeline = self .get_combinator_queries ()
401
401
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
403
404
if self .query .distinct :
404
405
distinct_fields = self .get_project_fields (
405
406
columns , ordering_fields , force_expression = True
@@ -409,6 +410,7 @@ def build_query(self, columns=None):
409
410
query .aggregation_pipeline .append ({"$group" : {"_id" : distinct_fields }})
410
411
query .project_fields = {key : f"$_id.{ key } " for key in distinct_fields }
411
412
else :
413
+ # Otherwise, simply project fields without grouping
412
414
query .project_fields = self .get_project_fields (columns , ordering_fields )
413
415
# If columns is None, then get_project_fields() won't add
414
416
# ordering_fields to $project. Use $addFields (extra_fields) instead.
You can’t perform that action at this time.
0 commit comments