Is there a way to list KV objects with custom sort order (eg, a metadata field)?

Seems currently the list() api only sorts by key …

It would be great to be able to sort by custom field in metadata

This is not currently possible and, while I don’t work for Cloudflare, I feel comfortable saying it is highly unlikely this will be ever be implemented.

A KV store is simply not designed for this kind of data access pattern - an SQL database might be more suitable.

If you really want to do this with KV (though I don’t recommend it), you’d have to create KV keys for each property you want to sort on.

For example if your namespace looks like this:

users:1 {"id":1,"name":"John"}
users:2 {"id":2,"name":"Emma"}
users:3 {"id":3,"name":"Sam"}

You could create new keys containing the name:

users-name:John:1 {"id":1,"name":"John"}
users-name:Emma:2 {"id":2,"name":"Emma"}
users-name:Sam:3 {"id":3,"name":"Sam"}

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.