How to query and filter with multiple arguments?
I'm trying to query workspaceMembers, where both userId and workspaceId are true. I tried below but it returned null:
I also tried with
withIndex
but it seems you can only use one. What is a good way to query with multiple arguments for filtering or indexing?
Update:
I got the following to work for my use case, but I'm still not sure if that is the most efficient or correct way to do it:
2 Replies
I believe for the
.filter
you want q.eq(q.field("userId"), arg.userId)
(and the same for workspaceId. The code snippet you pasted is checking if arg.userId
equals the "userId"
instead of checking the field.
You can define an index like .index("by_userId_workspace_id", ["userId", "workspaceId"])
and query it with something like .withIndex("by_userId_workspace_id", q => q.eq("userId", args.userId).eq("workspaceId", args.workspaceId)
@sshader You are brilliant. Thank you!