I'm currently trying to implement Tumblr-like user interactions such as reblog, follow, followers, commenting, blog posts of the people I'm currently visiting. There is also a requirement to display activity for each blog post.
I am stuck in creating the right schema for the database. There are several ways to achieve this kind of functionality (defining data structures embedded as blog posts and comments, creating a document for each action, etc.), but I couldn’t currently decide which one is the best in terms of performance and scalability.
For example, look at the implementation of the people I follow. Here is an example user document.
User = { id: Integer,
username: String,
following: Array of Users,
followers: Array of Users,
}
It seems trivial. I can manage the next field for each user action (follow / unsubscribe), but what if the user I'm currently running is deleted. Is it efficient to update all user records that follow the deleted user.
Another problem is creating a blog presentation from the people I follow.
Post = { id: Integer,
author: User,
body: Text,
}
So this is an efficient request for recent posts, for example:
db.posts.find( { author: { $in : me.followers} } )
source
share