Sorting collections

Hi,

I store matches history using one entry per match, but i do not know how to sort them directly from the API (sort them by date for example). I rode documentation but didnt found any information on sorting.

Am i missing something?

Thanks

@Mkarena The storage engine does not contain a way to sort keys in arbitrary ways. The way the data is stored on disk does follow an alphanumeric sort order though so one way you could solve this without special indexes would be to use a composite key to represent the logical key of the storage object. For example “{timestamp}_{matchid}” which would give you the ordered list of results back when you use storage list operations.

Alternatively you’ll need to add a custom SQL index which would allow you to access the data in a specific sorted order. If you can show the shape of the matches history you want to sort over in more detail I can suggest the best approach to use.

Hi @novabyte, thanks for the reply.

I join to the post an image representing the structure of a match history, for each match there is an entry for both players with the match_id as the key. I’m currently using the key (match_id) to retrieve single entry from backend so i don’t know if i can take “{timestamp}_{matchid}” as key.

I plan to use custom SQL but if you have better (native) solution, i’ll take it :slight_smile:

Thanks for help