I have MongoDB with a large collection of messages. All messages related to a specific groupId . So, we started by posting as follows:
Meteor.publish("messages", function(groupId) { return Messages.find({ groupId: groupId }); });
and subscription:
Deps.autorun(function() { return Meteor.subscribe("messages", Session.get("currentGroupId")); });
This caused me problems because initially the currentGroupId was undefined, but sill mongod would use the processor to search for messages using groupId == null (although I know they aren't).
Now I tried to rewrite the publication as follows:
Meteor.publish("messages", function(groupId) { if (groupId) { return Messages.find({ groupId: groupId }); } else { return {};
and / or rewrite a subscription to:
Deps.autorun(function() { if (Session.get("currentGroupId")) { return Meteor.subscribe("messages", Session.get("currentGroupId")); } else {
which initially helps. But as soon as currentGroupId becomes undefined again (as the user goes to another page), mongod is still busy reserving the database for the last signed groupId . So, how can I unsubscribe from a publication so that mongod stops being requested?
meteor
Dejan
source share