Sort in forge storage

I am using the complex query in forge storage as explained here, https://developer.atlassian.com/platform/forge/runtime-reference/storage-api-query-complex/#sort

The given below code allows me to sort by “employmentyear”. But i want to get the results sorted by “employmentyear” and “age”. How do we achieve this?

Here is my code based on the docs,

indexes:
  - name: by-gender-and-age
    range: 
      - employmentyear
    partition: 
      - gender

Usage:

await storage
  .entity("employee")
  .query()
  .index("by-age-per-gender", {
    partition: ["female"]
  })
  .sort(SortOrder.DESC)
  .getMany()

Hi @rajagopal,

After confirming with the engineering team, unfortunately, sorting with more than one column is currently not supported. One approach you could take is to sort it by employmentyear first, then sort the result set in your app.

Hope this helps.
Ian

Hi @iragudo,

Thank you for your quick response. It returns the 10 values as default and it can be extended up to maximum 20. So, applying the sort on client side wouldn’t be good enough right?

Loading all items is not a good practice to proceed on.

1 Like

Hi @rajagopal,

Thank you for your quick response. It returns the 10 values as default and it can be extended up to maximum 20. So, applying the sort on client side wouldn’t be good enough right?

Yes, you are correct, there is a max query limit of 20, and doing the second sorting on the client side for the result subset will not be enough unless you load all items first (which is not an optimal approach). The ideal scenario is to do the sorting when the query is called but sorting with more than one column is not yet supported.

Cheers,
Ian

When do we expect a sorting with more than one columns? Is there any timeline for this?

1 Like