Forge storage query - how is the order determined when it's returned

I’m planning out a new app and one of the things that I’m running into is that I’ll be relying on Forge’s Storage API to query for objects. Say I have 4 objects:

key-1: {}
key-2: {}
key-3:{}
key-4:{}

and I execute


await storage.query()
  // Filter the response to only keys that start with the string 'value'
  .where('key', startsWith('key-')).getMany()

Is there some way to pass in a sortKey or other way of guaranteeing that I will get the returned object to based on the key attribute (ie key-1, key-2, key-3, key-4)?

/Daniel

3 Likes

Hi @danielwester ,

From the Storage API reference:

Keys are lexicographically ordered - as such the Query API will return entities ordered by their key.

There’s no way to provide any alternate ordering.

Regards,
Dugald

2 Likes