M Zeeshan
M Zeeshan4mo ago

Compound index

Hello everyone, I need some help with Convex database indexing. I have a table named 'skills' and I have two separate indexes on the is_published and is_featured fields. I need to query the data based on both these fields. Initially, I thought of using a compound index, but it seems like the withIndex method doesn't allow multiple .eq() checks. Is there any way to efficiently filter by both these fields using the indexes? Any help would be greatly appreciated!
2 Replies
Hmza
Hmza4mo ago
yes it does https://docs.convex.dev/database/indexes/indexes-and-query-perf export default defineSchema({ books: defineTable({ author: v.string(), title: v.string(), text: v.string(), }).index("by_author_title", ["author", "title"]), }); const foundation = await ctx.db .query("books") .withIndex("by_author_title", (q) => q.eq("author", "Isaac Asimov").eq("title", "Foundation"), ) .unique();
M Zeeshan
M ZeeshanOP4mo ago
oh.... i didn't think about chaining

Did you find this page helpful?