-
Notifications
You must be signed in to change notification settings - Fork 240
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Mongo schema design #146
Comments
Hey @marco-fiset, I created the separate collections for Votes and Comments, so I'm probably the best one to answer as to the reasoning why. (and don't worry, I'm not offended). The way the database is designed now is really more of a relational design, and doesn't take much advantage of MongoDB's document-based design. However, I've found that the document-based databases are the most useful when each document is self-contained. It starts to break down when the connections between documents become important, as is the case with both Votes and Comments. Specific reasoning behind each one is below. I separated Comments into their own collection for two reasons:
I separated Votes into their own collection because of disadvantages of the other two options (or at least the only other two options I thought of).
I'm definitely open to discussing the alternatives, especially for Votes, but the pro's of separate collections seemed to outweigh the cons to me, with the added benefit of being familiar to users coming from a relational DB background. For reference, this reddit thread has over 10,000 comments. And the most popular HN post got over 4,000 upvotes. |
Oh, and something I forgot to mention is that nested comments (#153) would result in a pretty deeply nested comments subdocuments / vote arrays. |
@treygriffith Thanks for the clarification, I see you gave it a lot more thought than I did! It makes a lot more sense to me now. I exactly thought the same thing about multi-level comment nesting when I looked at the new issues this morning and saw #153. |
Is there a particular reason why Comments and Votes belong to their own collection?
I'd rather have comments and votes as nested properties of the NewsItem document, as it seems that they are pretty much always queried together.
I believe comments aren't really useful on their own, neither are votes. They really are tied to a particular item. NewsItems could have a
votes
property as an array of embedded documents, and comments be embedded in the NewsItem in the same way. Comments would also have their own an array of votes.I know it's kind of late to question such fundamental design decisions, but I'm concerned we might run into performance problems eventually. Plus it leads to pretty awful code for the frontpage, having to query each item's votes and comments in separate database request.
This is not supposed to be a rant in any way, I'm just trying to understand the reasoning behind the current design. English is my second language so please bear with me if I am not careful enough with my words, I don't mean to be offensive at all.
The text was updated successfully, but these errors were encountered: