docs icon indicating copy to clipboard operation
docs copied to clipboard

Add sorting + aggregations docs

Open cgm164 opened this issue 2 years ago • 2 comments

Describe the Request

Currently in the directus documentation, there is nothing (or I have not found it) regarding how to order the results through aggregated fields. After looking at the code and finding this PR: https://github.com/directus/directus/pull/19568, I realized that you could sort by, for example, a "count" result in descending order.

Example with SDK:

{
  aggregate: {
    count: 'id',
  },
  groupBy: ['company'],
  query: {
     sort: ['count.id']
  }
}

This would sort the result of count.id in descending order.

It would be great if this was added to the documentation in some way, since, currently from my point of view, there is a lot of information missing regarding how to take advantage of aggregation and grouping.

Maintainence Strategy

Every time the sorting strategy is changed in the aggregation.

cgm164 avatar Jan 09 '24 10:01 cgm164

Thank you @cgm164 ! Your research appeared to be very helpful cause I've already given up on attempting to sort by an aggregate field now I have learned the correct syntax.

sergey-kalitein avatar Jan 31 '25 20:01 sergey-kalitein