Publications not working as expected


#1

I have two publications.

The first pub implements a search. This search in particular.

 /* publications.js */
Meteor.publish('patients.appointments.search', function (search) {
    check(search, Match.OneOf(String, null, undefined));

    var query = {},
    projection = { 
         limit: 10,
         sort: { 'profile.surname': 1 } };

    if (search) {
        var regex = new RegExp( search, 'i' );

        query = {
            $or: [
                {'profile.first_name': regex},
                {'profile.middle_name': regex},
                {'profile.surname': regex}
          ]
     };

    projection.limit = 20;
}
   return Patients.find(query, projection);
});

The second one basically returns some fields

/* publications.js */
 Meteor.publish('patients.appointments', function () {
   return Patients.find({}, {fields:  {'profile.first_name': 1,
                'profile.middle_name': 1,
                'profile.surname': 1});
});

I’ve subscribed to each publication like so:

/* appointments.js */
Template.appointmentNewPatientSearch.onCreated(function () {
    var template = Template.instance();

    template.searchQuery = new ReactiveVar();
    template.searching = new ReactiveVar(false);

    template.autorun(function () {
       template.subscribe('patients.appointments.search', template.searchQuery.get(), function () {
          setTimeout(function () {
              template.searching.set(false);
          }, 300);
       });
    });
});


Template.appointmentNewPatientName.onCreated(function () {
    this.subscribe('patients.appointments');
});

So here’s my problem: When I use the second subscription (to appointments.patients), the first one doesn’t work. When I comment the second subscription, the first one works again. I’m not sure what I’m doing wrong here.