I have a collection containing messages and comments made available through a publication that takes several arguments. When I subscribe to the publication in two different templates, the messages load while the comments do not.
Here is my publication:
Meteor.publish("posts", function (category, domain, email, commentParent, limit) {
if (category == "anonymous") {
return Posts.find({category: category, domain: domain, reportedBy: {$ne: email}, reports: {$lt: 3}, commentParent: commentParent}, {fields: {owner:0}, sort: {createdAt: -1}, limit: limit});
} else {
return Posts.find({category: category, domain: domain, reportedBy: {$ne: email}, reports: {$lt: 3}, commentParent: commentParent}, {sort: {createdAt: -1}, limit: limit});
}
});
Here is the first subscription, which is working as intended:
Template.messages.onCreated(function() {
var self = this;
self.ready = new ReactiveVar();
self.autorun(function() {
var category = FlowRouter.getParam('category');
var email = Meteor.user().emails[0].address;
var domain = String(email.match(/@(.*)$/g));
var commentParent = {$exists: false};
var handle = PostSubs.subscribe('posts', category, domain, email, commentParent, 10);
self.ready.set(handle.ready());
});
Session.set('sort', 'new');
});
And here is the second subscription, which is not working:
Template.post.onCreated(function() {
var self = this;
self.ready = new ReactiveVar();
self.autorun(function() {
var category = FlowRouter.getParam('category');
var email = Meteor.user().emails[0].address;
var domain = String(email.match(/@(.*)$/g));
var commentParent = this._id;
var handle = PostSubs.subscribe('posts', category, domain, email, commentParent, 10);
self.ready.set(handle.ready());
});
});
As you can see, the two subscriptions differ only in the commentParent (messages using { $exists: false } and comments using their parent ID). I have both the messages and post templates on the same page. I am able to see my messages, but not the comments.
I apologize if my code is not structured well - I am a novice. Would anybody be able to point me in the right direction?