Making a Twitter-like timeline with MongoDB

前端 未结 3 1206
生来不讨喜
生来不讨喜 2020-12-29 13:16

What I need:

Suppose you\'re using MongoDB and you have a collection called users, and each user has a \"following\" array with user

3条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-29 13:32

    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.

提交回复
热议问题