"Special" publication?


#1

Is this doable with meteor:
I want to make a publication that alway returns eg. 5 posts matching some criterias (matches interest of the user, not rated). If the user rates a post, it gets out of the pub, and a new post is inserted to the pub so it matches the criterias. If the preference of the user changes dont update already published post just the new ones (preferences would modify the type of posts published)
Thanks a lot!


#2

Yeah, it sure is. Just implement the logic in the publish function on the server.


#3

Ok, thanks. When will the code inside meteor publish rerun?


#4

As the source data changes :slight_smile: If the criteria for the pub is that the post is unrated then once the document is rated it will no longer meet the pub criteria and another doc will take its place (if there is one) in this case. I have a similar thing going on for notifications in a project I’ve been working on. It pulls in the 10 most recent ‘likes’ which are marked as ‘unread’. If you click the ‘mark as read’ button in the list the item is removed and another (if it exists) takes its place.

example
Notifications.find({owner_id:Meteor.userId(),read:false},{limit:5});

NOTE: as long as your pub function returns a reactive thingy then this is the case…


#5

Ok, so pub reruns anytime the collection changes?


#6

As long as you don’t use some yet unsupported features like aggregation (except with some external packages), yes it will.


#7

Yeah, as @shad said. Collection cursors are reactive so the computation will be rerun when the cursor changes.

http://docs.meteor.com/#/full/reactivity