My subscribe code (inside onCreated() hook):
instance.sub = instance.subscribe('company.adminsList', instance.limit.get(), instance.search.get(), errorHandler);
return instance.autorun(() => {
let limit = instance.limit.get();
let search = instance.search.get();
console.log('limit:', limit, 'search:', search)
instance.sub = instance.subscribe('company.adminsList', limit, search, errorHandler);
// old documents from first sub is not removed, always here. I check this through the browser console.
});
My helper:
admins: function () {
return Users.find({
role: 'admin'
}).fetch();
},
So, old documents from the first subscription call are always on client. In example, by default my limit is 20; I change it to 40 => all OK, I change limit to 10 => I still have 20 documents on the client. Googling for hours, I didn’t find the answer.
My publication is working properly, I checked it:
Meteor.publish('company.adminsList', function (limit = 50, search = '') {
...
...
let cursor =Meteor.users.find({
company: Meteor.user().company,
role: 'admin',
// $or: or // needed for search
}, {
limit: limit,
fields: fields,
sort: {
createdAt: 1
},
});
console.log('found ', cursor.fetch().length) // All OK
return cursor;
}
To implement search, now I’m using methods. It’s working great, but the problem is methods are not reactive.