mongodb - Get the followers list and wether the current user follows them or not -
i'm trying achieve following cheapest cost , best performance: (please think of millions of documents):
have collection : followhip
{ “followee”: 12345, “follower”: 54321, “start”: isodate(“2013-08-21t12:34:00”), “last”: isodate(“2013-08-23t06:00:00”), “end”: isodate(“2013-08-23t07:50:23”)
}
last last scan date when follower
following followee
on profile page, followers (limited 10) , want check if current user follows followers.
naive solution query foreach follower , criteria : 'follower' = current user , 'followee' = follower , if result empty , return false, else true.
my question : there better solution ? map reduce or , i'm newbie in mongodb , maybe can me here
lot
you can use $in
operator don't have make ten queries, one, e.g.
// currentprofile.displayedfollowerids = [ 32434, 54354, 656536, ... ] db.followers.find( { followee : currentuser.id, follower: {$in : currentprofile.displayedfollowerids } });
map/reduce in mongodb not made ad-hoc queries; map/reduce operation has quite bit of overhead in mongodb , shouldn't used queries.
if have complex queries, might want @ aggregation framework.
Comments
Post a Comment