Array vs. Reference Relationship Performance
I'm looking to migrate to Convex from MongoDB. From what I've read in the docs, Convex leans more to the normalized/relational way of storing data. MongoDB is on the totally opposite side and is denormalized with no built-in relationships. Coming from this background I have a question:
If I have a one-to-many relationship, should I put an array of child ids in the parent document, or put a reference to the parent document id in the child document?
The aim of my question is toward performance, not necessarily DX wins/loses. I'm newer to Convex, so feel free to add as much context as you can for the new guy.
2 Replies
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!
I'm answering my own question here (I assume it's helpful do this?). Arrays can't be cached in Convex, so querying a parent based on a child id is slow (each array of child ids must be searched individually). This article was very helpful: https://stack.convex.dev/relationship-structures-let-s-talk-about-schemas
Relationship Structures: Let's Talk About Schemas
In this post we’ll look at some patterns for structuring relationships in the Convex database.