w3c
w3c•3w ago

Querying array fields in Convex

I have a question about querying array fields in Convex. In my schema, articles have a 'tagIds' array field:
articles: defineTable({
tagIds: v.array(v.id("tags")),
// other fields...
}).index("by_tags", ["tagIds"])
articles: defineTable({
tagIds: v.array(v.id("tags")),
// other fields...
}).index("by_tags", ["tagIds"])
How can I query for all articles that contain a specific tagId, regardless of what other tags they might have? Is array filtering possible in the query, or do I need to query all articles and filter in memory?
3 Replies
Convex Bot
Convex Bot•3w ago
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!
lee
lee•3w ago
this article uses that exact example https://stack.convex.dev/complex-filters-in-convex
Using 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.
w3c
w3cOP•3w ago
thank you. 😄

Did you find this page helpful?