[mongodb-user] schema design for a social network

868 views
Skip to first unread message

Alan B

unread,
May 15, 2010, 6:18:36 AM5/15/10
to mongodb-user
hi all, 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 user 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

--
You received this message because you are subscribed to the Google Groups "mongodb-user" group.
To post to this group, send email to mongod...@googlegroups.com.
To unsubscribe from this group, send email to mongodb-user...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/mongodb-user?hl=en.

sdotsen

unread,
May 15, 2010, 9:38:08 AM5/15/10
to mongodb-user
See Dwight's post -> http://dmerr.tumblr.com/post/463694595/just-for-fun-a-single-server-twitter-design

For the profile photo, you're going to need to make two trips to the
DB.
One to grab the subscribers and then back to the collection to grab
the photo.
Reply all
Reply to author
Forward
0 new messages