Hi,
I'm currently designing a database structure (it's strange to avoid the term scheme here) and ran into some issues. I am going to motivate my question by a similar example.
Think of a database for blog entries. Each blog entry has 0..n comments, 0..m tags and 0..r user votes (up/down) for entries.
Of course I could put everything together in one big JSON object and have one common object per entry including comments, tags and votes as fields.
That's however prone to conflicts when there are many concurrent changes (at least in my real application there are). So I think about to split up my structure into several documents. One per entry, and for each entry one (collection-)document for comments, one for tags and one for votes.
I'd also set up a fix name schema. Blog entries have UUID when created, the documents for comments, tags and votes are named <blog-entry-uuid>:(tags|votes|comments)
.
Thus, I can always build the ID of the referred documents just by knowing the id of the blog post. When using views, I can use the power of view collation to "join" or take advantage of include_docs=true
.
By using update handlers, I can further minimze the change of conflicts for adding a comment etc. The handler just takes the new comment, and puts it into the <blog-entry-uuid>:comments
document.
Is this a feasible approach or are there better ways for joins? Is it bad practice to build IDs that way?
Thanks in advance