Klaus N Klaus N - 1 month ago 14
Javascript Question

Meteor - Publish array - but how do i Subscribe?

I have this Publish on the server

Meteor.publish('events', function(){
var currentUserId = this.userId;
var events_private = Events.find({ UserId: currentUserId });
var events_internal = Events.find({ 'Option.option_vis' : "internal"});
var events_public = Events.find({ 'Option.option_vis' : "public"});
if (events_UsersOwn){
return eventsForUser = [
events_private//
events_UsersOwn,
events_public
]
}
return this.ready();
});


On the client I would like to subscribe. But how do I get in touch with the behind data? I have tried following:

Meteor.subscribe('events.events_private');


And ind the method

Template.eventTemplate.helpers({
returnUsersEvents: function(){
console.log(Events.find({}).fetch());
}
});


I am doing it wrong / understanding it wrong, but I think that i'm close. Thanks.

Answer

When returning an array of cursors from a publish function, each cursor must be from a different collection. You have 3 cursors from the Events collection. This is not supported.

You need to create 3 separate publications.