'schema' design for a social network

Posted by Alan B on Stack Overflow See other posts from Stack Overflow or by Alan B
Published on 2010-05-15T10:20:55Z Indexed on 2010/05/15 10:24 UTC
Read the original article Hit count: 418

Filed under:
|

I'm working on a proof of concept app for a twitter style social network with about 500k users. I'm unsure of how best to design the 'schema'

should I embed a user's subscriptions or have a separate 'subscriptions' collection and use db references? If I embed, I still have to perform a query to get all of a user's followers. e.g.

Given the following user:

{
 "username" : "alan",
 "photo": "123.jpg",
 "subscriptions" : [
    {"username" : "john", "status" : "accepted"},
    {"username" : "paul", "status" : "pending"}
  ]
}

to find all of alan's subscribers, I'd have to run something like this:

db.users.find({'subscriptions.username' : 'alan'});

from a performance point of view, is that any worse or better than having a separate subscriptions collection?

also, when displaying a list of subscriptions/subscribers, I am currently having problems with n+1 because the subscription document tells me the username of the target user but not other attributes I may need such as the profile photo. Are there any recommended practices for such situations?

thanks Alan

© Stack Overflow or respective owner

Related posts about mongodb

Related posts about nosql