MongoDB get last 10 activities -


in social network want feed member a , member a following lets 20 category/member.
when category/member(followed member a) activity inserted collection called recent_activity :

{    "content_id": "6", // content id member following    "content_type_id": "6",// content type (category , other member)    "social_network_id": "2", // action category did (add/like/follow)    "member_id": "51758", //member    "date_added": isodate("2014-03-23t11:37:03.0z"),    "platform_id": numberint(2),    "_id": objectid("532ec75f6b1f76fa2d8b457b"),    "_type": {      "0": "altibbi_mongo_recentactivity"    }  } 

i want when member a login system last 10 activities categories/member

my problem :

how 10 activities categories/members.

it better in 1 query or loop.

for use case, i'd suggest invert logic , keep separate object of last 10 activities member kept up-to-date time. while solution more write-heavy, makes reading trivially simple , can extended easily. i'd blatantly advertise blog post wrote while ago news feeds mongodb outlines approach.

this 'fan-out' approach might seem overly complex @ first, when think importance filtering / ranking (a la facebook), push messages particularly important events (facebook, twitter) or regular digest emails (practically all), 1 location in code perform logic.


Comments

Popular posts from this blog

android - Get AccessToken using signpost OAuth without opening a browser (Two legged Oauth) -

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: mockito -

google shop client API returns 400 bad request error while adding an item -