I think I know the answer to this but I
I think I know the answer to this, but I want to make sure.
Consider this schema:
There is no way to query for all threads where a certain users._id is a member?
9 Replies
With this data model, there's not a way. One strategy is to have a separate table for thread members
That way you can index on memberId or threadId
if you want something easy & inefficient, you can do the filter in javascript -- do a
.query('threads').collect()
and then filter
on the returned arrayThanks! This is the approach we are implementing. Just wanted to be sure before we change the schema 🙏
Another advantage of the separate table is that it's easy to query for all threads for a member (in case you want to show that in one of your views) as well as all members for a thread.
What about helpers from convex?
He might use this one as well
I mean asyncmap
That will probably get out of hand pretty soon in production...
Functional Relationships: Helpers
In this post, we’ll look at some helper functions to help write code to traverse relationships in a readable, predictable, and debuggable way.
Convex actually internally uses something similar for
team_member
- since you can be on more than one team and teams can have more than one member! Same idea.Thanks a bunch everyone, this is super helpful! I haven't read the helpers article yet, but will that run on the server in a best-practices way?
I think I got what I need. Thanks a again good people!