mc9
mc9

Reputation: 6341

Passing arguments in Meteor.subscribe

When can I pass an argument when I am subscribing to a published collection?

I am publishing my collection like this:

Meteor.publish('recent-posts', function (options) {
  var limit = options.limit;
  return Posts.find({}, {sort: {date: -1}, limit: limit});
});

In my routes file, I can pass {limit: 5} as options like this, and it works:

...
waitOn: function () {
  return Meteor.subscribe('recent-flights', {limit: 5});
}
...

What confuses me is that this also works:

...
waitOn: function () {
  return Meteor.subscribe('recent-posts', {date: this.params.date});
}
...

The second example subscribes me to all the posts with a certain date value.

Why does it work? It seems like I am passing {date: this.params.date} as options. But I have not defined anything about date in my Meteor.publish.

Upvotes: 2

Views: 1942

Answers (1)

halbgut
halbgut

Reputation: 2386

Nothing in Meteor would lead to such a behavior, at least as far as I can tell from the source code. I also tested your example in a "clean" meteor instance. An it did not behave as you describe. So it must be something in your code doing this. It could also be, that you aren't describing your problem correctly.

I also noticed that in you are using two different subscriptions in your example; recent-posts and recent-flights. So that might be the source of your confusion.

Upvotes: 1

Related Questions