0

I'm building a social network very similar to Twitter, in which users can see a feed with content posted by users they follow. Users can like and re-post (i.e. "Retweet") posts. Re-posted content works just like it does on Twitter. If a user re-posts a post, it will get shown to their followers.

My database is mongo db. Posts go into a posts collection. But I'm wondering about the best way to include a re-post so that it gets queried along with the posts for the feed query. I've thought about doing it several ways:

  • Insert a re-post doc in posts docs collection, but add a field referencing the clip being re-posted. Not sure whether to repeat the re-posted post's data here.
  • Use a separate collection for re-posts. Query both the posts and re-posts collections when retrieving the feed.
  • Don't insert a re-post doc at all. Include a sub-document in the post's document that includes the re-poster info. When querying for the feed, use re-posters as part of the criteria. Problem is, the application will have no way to know if the post was selected bc the user follows the author or a re-poster, or which reposter.

Not sure what the best practice is for this. Advice is much appreciated.

  • 1
    This is not necessarily directly related to your question, but you may want to have a look at this blog post on "social inbox" schema designs in MongoDB. blog.mongodb.org/post/65612078649/… – helmy Oct 31 '14 at 21:33
  • For no3 document and sub-document will have an _id that will included on the re-post so you can track the originator. What is scary for no3 is the size of the document might become huge. I would combine no2 and no3. A sepetate collection for the subdocs of no3 – Antonios Nov 1 '14 at 16:02
0

For anyone who's curious, I ended up doing it the first way: Insert a re-post doc in posts docs collection. The doc inserted doesn't contain any of the re-posted doc's info, just a reference to its ID under a "reposted_id" field. It also includes info about the reposter.

The query for the feed will match either the author ID or the reposter ID. From the results of that query, we remove duplicate posts; i.e. if the user follows both the original author and the reposter, or multiple reposters, they should only see the post once. Then the post info is queried for each unique re-posted post.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.