Can I setup an index with array list field
In my
users
table, I'm adding a new key roles
which is an array. Is it possible to declare an index based on that field? If yes, how could I run a query using the .withIndex
api where the values of the field are in a list? If this is not possible, is there a pattern or workaround I could choose to "limit" queries upon the (very large) users
table, based on roles
?3 Replies
Thanks for posting in <#1088161997662724167>.
Reminder: If you have a Convex Pro account, use the Convex Dashboard to file support tickets.
- Provide context: What are you trying to achieve, what is the end-user interaction, what are you seeing? (full error message, command output, etc.)
- Use search.convex.dev to search Docs, Stack, and Discord all at once.
- Additionally, you can post your questions in the Convex Community's <#1228095053885476985> channel to receive a response from AI.
- Avoid tagging staff unless specifically instructed.
Thank you!
.withIndex
lets you select a contiguous range of the index, which I don't think works with your roles array. Check out this article which describes a similar use-case with several solutions https://stack.convex.dev/complex-filters-in-convexUsing TypeScript to Write Complex Query Filters
There’s a new Convex helper to perform generic TypeScript filters, with the same performance as built-in Convex filters, and unlimited potential.
if the roles are totally ordered (like "owner", "writer", "reader", "commenter") you could potentially sort them, e.g. if you want to filter to users with role >= "writer"