File tree Expand file tree Collapse file tree 1 file changed +7
-11
lines changed Expand file tree Collapse file tree 1 file changed +7
-11
lines changed Original file line number Diff line number Diff line change @@ -401,19 +401,15 @@ def build_query(self, columns=None):
401401 else :
402402 # If we query distinct
403403 if self .query .distinct :
404- distinct_fields = self .get_project_fields (columns , force_expression = True )
404+ distinct_fields = self .get_project_fields (
405+ columns , ordering_fields , force_expression = True
406+ )
405407 if not query .aggregation_pipeline :
406408 query .aggregation_pipeline = []
407- query .aggregation_pipeline .extend (
408- [
409- {"$group" : {"_id" : distinct_fields }},
410- {"$addFields" : {key : f"$_id.{ key } " for key in distinct_fields }},
411- ]
412- )
413- if "_id" not in distinct_fields :
414- query .aggregation_pipeline .append ({"$unset" : "_id" })
415-
416- query .project_fields = self .get_project_fields (columns , ordering_fields )
409+ query .aggregation_pipeline .append ({"$group" : {"_id" : distinct_fields }})
410+ query .project_fields = {key : f"$_id.{ key } " for key in distinct_fields }
411+ else :
412+ query .project_fields = self .get_project_fields (columns , ordering_fields )
417413 # If columns is None, then get_project_fields() won't add
418414 # ordering_fields to $project. Use $addFields (extra_fields) instead.
419415 if columns is None :
You can’t perform that action at this time.
0 commit comments