What I need:
Suppose you're using MongoDB and you have a collection called users
, and each user has a "following" array with user _id
s of the people he's following. Then you have another collection statuses
, with each status containing the _id
of its author.
How do you display to a certain user all the statuses added by people he's following?
What I tried:
I put all the users _id
s that the current user is following in an array (I'm using PHP), then I used it to find all the statuses by those users using $in
.
The question:
Is this the best solution?
I can't see any other way too, i implemented such thing before and didn't have a problem.
On your case, it should be sth like this, you pass certain user's $follower_ids
array as an argument to your function:
$query = array("status_owner_id" => array('$in' => $follower_ids));
$cursor = $mongo->yourdb->statuses->find($query);
And if you index statuses (if you have enough ram to do so) upon owner_id you'd get the results really fast.
Hope it helps, Sinan.
Yea, I do the exact same thing. See what Dwight Merriman suggested on his blog.
http://dmerr.tumblr.com/post/463694595/just-for-fun-a-single-server-twitter-design
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With