many-to-many: store and query
I have a use case where there are about 60 possible choices, and each user can select between 1–60 of them.
Currently I’m storing them in a separate join table like:
{ userId, choiceId }
This works for filtering (e.g. “find users who selected X”), but with 10k users it could mean 100k–600k+ rows, which feels heavy.
I’m considering other approaches:
Store choice IDs in an array inside the user document. (But then how to query efficiently by choice?)
Use a bitmask (60 choices = fits in a 64-bit int) for compact storage. But Convex doesn’t seem to support bitwise queries directly.
A hybrid approach — store array/bitmask in the user doc for compactness, and maintain a separate index table for filtering.
What’s the recommended way in Convex to store and query this kind of many-to-many preference data efficiently?
1 Reply
Thanks for posting in <#1088161997662724167>.
Reminder: If you have a Convex Pro account, use the Convex Dashboard to file support tickets.
- Provide context: What are you trying to achieve, what is the end-user interaction, what are you seeing? (full error message, command output, etc.)
- Use search.convex.dev to search Docs, Stack, and Discord all at once.
- Additionally, you can post your questions in the Convex Community's <#1228095053885476985> channel to receive a response from AI.
- Avoid tagging staff unless specifically instructed.
Thank you!