I have multiple subscriptions on the search results page of a Meteor app. So in the middle is a template for the search results of items, on the left is a template for trending items, and on the right is a template for related items.
On the server I publish a related items (on the right) by querying the Mongodb using a text search which is only possible on the server since minimongo doesn't have that functionality.
But I am also subscribing to a trending items (on the left) which grabs a different set of those same items. In isolation, I receive the correct results, that is, when I comment out the code for the trending items, I get the right results for the related items. And vice versa. But when both are left, it appears they are drawing from the same collection on the client and the results are distorted.
Is there any way to handle multiple subscriptions on the same page?
trendingItems.js
Meteor.subscribe('trendingItems');
Template.trendingItems.helpers ({
trendingItems: function() {
results = Items.find({}, {
fields : { follows : 1, title: 1, itemId: 1 },
sort : { follows : -1 },
limit : 5
}).fetch();
return results;
}
});
relatedItems.js
Template.relatedItems.helpers ({
relatedItems: function() {
return Items.find();
}
});
publications.js
Meteor.publish('relatedItems', function(searchString) {
return Items.find(
{ $text: { $search: searchString } }
);
});
Meteor.publish('trendingItems', function(options) {
results = Items.find({}, {
fields : { follows : 1, title: 1, itemId: 1 },
sort : { follows : -1 },
limit : 5
}).fetch();
return results;
});
A general solution to the problem of handling multiple subscriptions, rather than a specific solution that solves just this problem, is desirable.