Resubscribe after subscription not working, takes a couple of minutes

Hello Guys,

Just in case some masters there are still awake, I encountered problem when trying to control the subscription on client side. The objective is to subscribe only those data that are match with the terms I entered on a search field. So in my publication I have this way of implementation:

Meteor.publish("Customers", function(param, param1) {
  let _project = (param) ? param : {};
  let _clr = (param1) ? param1 : {};
  console.log(_project);
  return Customer.find(_project, _clr);
});

lets just focus on params because that is the projection.

Now on my client side I put below codes on time when button is hit or clicked.

_subsc_Customers = Meteor.subscribe('Customers', _where, {limit : 100});

the _where variable handle the condition for projection on my publication.

The codes doesn’t have error but it only works on first search (at the same time first subscription of course) then I change the search input field value to something i.e ‘testing’ and this time it doesn’t work. What I have to do is to reload the page and search the ‘testing’ keyword again and this time I got the result.

Any idea why this happened?

(The reason why I have to do this type of subscription is because we have thousands of records)

TY

Basically, publications are not reactive. They will only ever run once unless they are re-subscribed to. In most cases, the canonical way to address this is to put the subscribe into an autorun which is dependent on a reactive variable. In your example, you want the _where parameter to be reactive (for example, the result of a ReactiveVar#get).

You can see a Blaze example of the sort of thing here.

thanks for the reply, but I tried already the autorun with session that handle the _where conditions but still it only works once. Like what I’ve said above I only want to subscribe those data that matches with my _where conditions when button is clicked. And if I there search term is changed I want to re-subscribe again with the new _where conditions but it doesn’t allow me. :frowning:

Then we need to see more code.

Sorry for late reply, I’ve fixed this already by implementing the subscription twice with .stop()