Resubscribe without reactivity

Hello,

I’m building an app with meteor + react and using subscription parameters to do server side search. So in client I only have collection.find({}) without any params. I can’t do search in client because of high amounts of data and complex queries which are not supported by minimongo.

And the problem is that I can’t “resubscribe” without meteor reactive methods. See code bellow what I mean:

This works:

class {
constructor(props, context)
{
Session.setDefault(“options”, {});

    Tracker.autorun(function () {
        Meteor.subscribe("Data", Session.get("options"));
    });
}

FiltersUpdated = (options) => {
    Session.set("options", options);
}

}

This doesn’t work:

class {
constructor(props, context)
{
}

FiltersUpdated = (options) => {
    Meteor.subscribe("Data", options);
}

}

The problem is that when I don’t use Tracker it doesn’t resubscribe but creates a new subscription instead. So as a result search data only gets added to client and if items no longer match the filters they don’t get removed. I checked internal server data and indeed multiple subscriptions are created instead of modifying existing one. The first code example runs perfectly fine though but it has a lot of boilerplate code and looks ugly. I bet there must be some kind of way to make the second example work. I guess the subscription in Tracker saves some kind of id to resub later?

Thanks

Offtopic: there is something wrong with code formatting, I couldn’t get it to align properly

I don’t quite follow the issue you’re describing of items that no longer match filters aren’t being removed, but I’ll suggest another option altogether. Have you considered using something like meteorhacks:search-source? It will reactively take care of your search data for you. It works quite well. I have a small POC built using it with React and Solr if you’re interested.

I’ve seen this package before but haven’t looked deeper. It now actually seems to be exactly what I need. Thanks for a suggestion :smiley:

However, I would still like to figure out what’s wrong with my code. As I will probably encounter similar problems in the future while using meteor with react.