Reputation: 2837
I have the following pub in my Meteor app and sub in my iron router, however for the data function I'm not getting anything back, if I change my publish to topics and not public topics then it's fine. But that can't be correct as then have the same publish twice and I get a meteor message about it. Not sure what I'm doing wrong.
I would like to have a set of public topics based on the url
Meteor.publish('topics' , function() {
return Topics.find({$or:[{userId: this.userId},{collaboratorsIds: this.userId},{inviteeId:this.userId}]});
});
Meteor.publish('publicTopics' , function(permalinkUser,permalink) {
return Topics.find({$and:[{permalinkUser: this.permalinkUser},{permalink: this.permalink}]});
});
and in my iron-router I have the following
this.route('topicPublic', {
path: 'public/:permalinkUser/:permalink',
layoutTemplate: 'layoutApp',
waitOn: function(){
return [Meteor.subscribe('publicTopics', this.params.permalinkUser,this.params.permalink)]
},
data: function(){
return Topics.findOne({$and:[{permalinkUser: this.params.permalinkUser},{permalink: this.params.permalink}]});
}
});
Upvotes: 0
Views: 142
Reputation: 2837
Need to remove "this" -- my mistake wasn't paying attention I copied the return from the router data function.
Upvotes: 0
Reputation: 2200
Your publicTopics publish function is wrong. If you pass a parameter to a function you don't use this.permalinkUser inside function but just permalinkUser. Learn more about functions on w3schools.
Meteor.publish('publicTopics' , function(permalinkUser,permalink) {
return Topics.find({$and:[{permalinkUser: permalinkUser},{permalink: permalink}]});
});
In your topics publish function you use this.userId because it's property of Meteor object.
Upvotes: 0