My publish and subscribe functions aren't working

I want to display a list of all of the users, on the server side I’ve created a publish function and on the client side the subscription function but for some reason none of my users appear in my database, I’ve removed autopublish

Here is my client side code

Template.Directorio.onCreated(function () {
    this.autorun(() => {
        this.Meteor.subscribe('AllUsers');
    });
})

And here’s my server side code

Meteor.publish('AllUsers', function() {
    return Meteor.users.find({})
})

Just plain simple publish and subscription to look for all of the users that are supposed to appear in Meteor.users. Also I’ve tried writing Meteor.users.AllUsers in both sides and have the same result.

UPDATE: I changed the collection to profiles because I’m using onCreateUser, just to give it a try and it works. ^^!

try this.Meteor.subscribe(‘AllUsers’); outside autorun and check if the DB appears. the syntax looks ok to me. So it might be a problem with autorun. This would not solve your problem but would help you detect where the issue is.

Please provide repo with reproduction.

autorun used like this will not stop the pub/sub from working. However, it’s completely redundant when used without reactive parameters in the subscription. The problem may be the way the subscription has been referenced (this.Meteor.subscribe instead of this.subscribe or Meteor.subscribe).

Template.Directorio.onCreated(function () {
  this.subscribe('AllUsers');
});

is how I would have expected it to be defined.

3 Likes

Yeah I also forgot to mention that I changed that, but thanks for clarifying the reason, I’m still kinda new in meteor :stuck_out_tongue:

1 Like