bambam
bambam

Reputation: 1

Meteor - can't pass variables in subscribe

I'm having problems with Meteor's subscribe. My goal is to search through my collection given criteria from user input form and spit back documents that match. My code works when I hard code let's say Meteor.subscribe('byProductAndBrand',1, 2) or whatever number instead of day and month. I tried the same numbers for day and month from the website, and it doesn't return any results. My variables seem to get the values from the html form because they print in the console, but for some reason they don't get passed in subscribe.Any suggestions?

The ScheduleList collection is just a bunch of documents with a certain hour, day, and month.

In the client:

Template.myform.events({
    'click #submit' : function(event, template){
        event.preventDefault();
        Session.set('day', template.find('#day').value);
        Session.set('month', template.find('#month').value);
        var day = Session.get('day');
        console.log(day);
        var month = Session.get('month');
        console.log(month);
        var instance = Template.instance();
        if(instance.byProductAndBrandHandle != null){
            instance.byProductAndBrandHandle.stop();
        }
        instance.byProductAndBrandHandle = Meteor.subscribe('byProductAndBrand',day, month);
    }
});

In the server:

Meteor.publish('byProductAndBrand', function(day, month){
    var d = day;
    var m = month;
    return ScheduleList.find({day:d},{month: m});
});

Upvotes: 0

Views: 118

Answers (2)

Michel Floyd
Michel Floyd

Reputation: 20246

Incidentally, one easy way to debug issues like this is to put a debugger; statement in your Meteor.publish function and then:

$ meteor debug

from the console. Then launch the Node Inspector in your browser at

http://localhost:8080/debug?port=5858

Then you can validate the parameter parsing and also double check your logic interactively. Sander's answer is correct though.

Upvotes: 1

Sander van den Akker
Sander van den Akker

Reputation: 1554

The query limit in your server publication is incorrect, it should be:

ScheduleList.find({day:d, month: m});

Upvotes: 1

Related Questions