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
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
const users = await prisma.user.findMany({
where: {
interests: {
hasSome: ['AI', 'frontend'],
},
},
});
something like this
await filter(ctx.db.query("user"), (user) => args.interests.some((interest) => user.interests.contains(interest))).collect()
Where does filter come from please? I'm having same issue
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.
It worked, thanks!!
Do I install the package too?
thanks