views:

307

answers:

1

I'm trying to implement blog post storage using mongo db.

I've got two domain entities:

"Blog post" and "Author"

Currently I've added AuthorId property to blog post entity. Is that the right approach to store relation between objects?

A: 

Currently I've added AuthorId property to blog post entity. Is that the right approach to store relation between objects?

I'd say no. You are "supposed" to store everything you need in a blog document in a denormalized way (e.g. the blog post, the comments, the tags, etc). So if you want to show the Author's name, you should add it to the blog document. This would allow to fetch an entire page's data with a single query, which is kinda the point of a document-oriented database.

Pascal Thivent
renaming a user becomes a very expensive call though!
Blankman
@Blankman: True. Still, I think that the philosophy of document oriented db is to fetch a whole document in one query. And by the way, what is the ratio of [renaming a user]/[showing a blog post]? I think it's **very** low.
Pascal Thivent
@Blankman, You can do it async and updates are very fast in MongoDB because MongoDB has update-in-place. You can also index the blog posts on authorid.
TTT
Pascal, yes in this case its low, but say you had to display the user's current points. You'd have to make another call for that as that would become stale very fast potentially.
Blankman
@Blankman, That's true, something like the reputation points of a user change often but staleness is often acceptable.
TTT
As I heard some document oriented db has multi dimensional structure so authorid could be used in both document objects: author and blog post.
Alexey Zakharov
@Blankman: Well, @TTT gave you a pretty good answer. I'd just add one thing: nothing forces you to use a document oriented db, it won't fit in every situation.
Pascal Thivent
TTT staleness is acceptable but not points! Say you are reading a 1 month old post by John Skeet, his points will be WAY off. Points has to be near realtime, maybe 1 hour stale (if that's what you meant that I agree).
Blankman
@Pascal I agree, just making the point on 'points' :)
Blankman
@Blankman, You don't have to see exactly how many points Jon Skeet has. You can show a rounded number, for instance 190k. This means that you only have to update if Jon Skeet gains another 1000 points.
TTT