Reputation: 5289
I'm from SQL world, so please, don't ask me that there are no tables, relations, etc in NoSQL, I know it, but it's difficult for me to understand how I can keep news in categories without relations.
So, imagine that we want to keep in database news, categories for news, tags, user profiles and comments for news by users. With SQL I think that this task can be solved with architecture like this (don't look at syntax, it is pseudocode):
categories ( id, title )
news (id, title, content, category_id)
users (id, first_name, last_name, homepage_url)
news_comments (id, news_id, user_id, comment)
tags (id, title)
news_tags (news_id, tag_id)
How this task can be solved with MongoDB / CouchDB / NoSQL? I'm interested in good architecture, I don't need to know about something specific like indexes.
Upvotes: 0
Views: 263
Reputation: 8805
In general, you need to denormalize your data. Your "news" record would look like:
news (id, title, content, category_title, [tags]) # that is list of tags
or technically more precise, something like:
(id, type=news, title, content, category_title, [tags])
You can filter by "foreign key" so having
news_comments (id, news_id, user_id, comment)
is not much of an issue if you want to select comments for a given news, but if you want to display user's first_name
you would probably want to include that data in comment record itself.
So what if user changes it's data after commenting?
there is an option 3 you find all comments and update them, but if that's common enough case, you probably need relational database to begin with.
Upvotes: 1