0

In my application I have a collection that is a list of videos, which bring only the videos of the authenticated user and would like to publish the same collection to bring the latest 5 videos but from all users. I'm doing the following but without success:

//CLIENT
PlayLists = new Meteor.Collection('playlists');
LatestLists = new Meteor.Collection("latestlists");

Meteor.autosubscribe(function () {
    Meteor.subscribe('playlists', Session.get('listkey'));
    Meteor.subscribe('latestlists');    
});

Template.latestlist.latest = function(argument) {
    return LatestLists.find({});
};
Template.list.playlist = function(argument) {
    return PlayLists.find({});
};

//SERVER
PlayLists = new Meteor.Collection('playlists');
LatestLists = new Meteor.Collection("latestlists");

Meteor.publish('playlists', function (playlist) {
  return PlayLists.find({}, {user:this.userId()}); 
});
Meteor.publish('latestlists', function(){
  return PlayLists.find({}, {sort:{when:-1}, limit:5}); 
});

When i run the app, my latestlist collection allways is empty. what is the best way to achive this?

Thanks in advance

Topicus
  • 1,394
  • 1
  • 15
  • 27

1 Answers1

1

The Meteor livedata package does some magic with collections & subscriptions when you return a Cursor in Meteor.publish(..).

Tom Coleman gave a good example of how you can bend Meteor to do what you are looking for here: In Meteor how can I publish one server side mongo collection under different names?

Essentially you should do as he suggested, either:-

  • Call that internal _publishCursor function passing in your PlayLists.find({}) cursor and latestlists as your subscription name.

-Or-

  • Copy the _publishCursor function and put it into a package for reusability.

Both approaches would work and I'd favour the latter as I am always wary about calling internal functions as they are liable to change underneath you.

Community
  • 1
  • 1
Jabbslad
  • 546
  • 3
  • 10