funkyeah
funkyeah

Reputation: 3184

what is passed to the server on a meteor subscribe argument?

I have seen code where people subscribe to collections in Meteor and the subscription passes and argument. E.g.

Meteor.subscribe('collection', arg);

and the related

Meteor.publish('collection', function(arg) {
   return Collection.find(arg);
});

the question is, where does that argument come from or what passes the argument to the subscribe method/function?

Upvotes: 1

Views: 721

Answers (1)

David Weldon
David Weldon

Reputation: 64312

Typically these will come from a session variable, for example:

Tracker.autorun(function() {
  var groupId = Session.get('currentGroupId');
  Meteor.subscribe('invitationsForGroup', groupId);
});

Here we are subscribing to a collection representing the invitations for the current group. Note that the subscription is made inside of an autorun so it will automatically update whenever currentGroupId changes.

More details and another example can been seen here.

Upvotes: 1

Related Questions