wruxW
Convex Community12mo ago
36 replies
wrux

Query, filtering array of IDs

I have a jobs schema which has a skills property which is just an array of ID references.

jobs: defineTable({
  title: v.string(),
  clientId: v.id('users'),
  skills: v.optional(v.array(v.id('skills'))),
}).index('by_clientId', ['clientId'])


In my application, I want to filter by skills. What is the best way to query a set union on skills and my args.

I know the following query won't work. I'm just wondering if something like this is possible:

let jobsQuery = ctx.db
  .query('jobs')
  .filter((q) => q.eq(q.field('status'), args.status))
  .filter((q) => {
    q.and(q.field('skills'), q.contains(q.field('skills'), args.skills))
  });
Was this page helpful?