rajat.abcx
rajat.abcx5mo ago

How to do array filter with multiple values?

I have a user schema with an interests column, which have array to string values, and people can filter based on multiple interest all the selected values will be applied in or relation, but the current "filter" method in convex-helper helps to filter only one value, is there another approach to do it? if I have to change to change my schema that's also fine.
8 Replies
lee
lee5mo ago
i'm not sure i understand what kind of filter you're trying to do. Could you write the filter in sql or pseudocode? That might make it easier to translate into convex queries
rajat.abcx
rajat.abcxOP5mo ago
const users = await prisma.user.findMany({ where: { interests: { hasSome: ['AI', 'frontend'], }, }, }); something like this
lee
lee5mo ago
await filter(ctx.db.query("user"), (user) => args.interests.some((interest) => user.interests.contains(interest))).collect()
Tekipeps
Tekipeps5mo ago
Where does filter come from please? I'm having same issue
lee
lee5mo ago
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.
rajat.abcx
rajat.abcxOP5mo ago
It worked, thanks!!
Tekipeps
Tekipeps5mo ago
Do I install the package too?
No description
Tekipeps
Tekipeps5mo ago
thanks

Did you find this page helpful?