Meteor.publish is not executed

I’m a bit stumped on this and I’m not really seeing where the problem lies. First I thought it was something on the directory structure… but, no. This is on Meteor beta.8, by the way.

I first stumbled across this when I wanted to publish all users to the admin for an admin panel. I noticed that the collection on the client side remained empty. First I though it was the alanning:roles package but that one seems to be innocent.

The code in question on a shared file:

AllUsers = new Mongo.Collection("allusers");
Test = new Mongo.Collection("test");

console.log("Shared");

if(Meteor.isServer) {
    console.log("Server");
    Meteor.publish("allusers", function() {
        console.log("Test");
        return Meteor.users.find({});
    });
    Meteor.publish("test", function(){
        console.log("Test2");
        return Test.find({});
    });
}

What I’m seeing on the server terminal:

Shared
Server

What I’m seeing on the client terminal:

Shared

What I’m not seeing:

Test
Test2

It’s a bit of a mystery to me.

Why are you using Meteor beta versions ?

Where is your client code subscribing?

1 Like

Ah, I see. So I have to subscribe for the code to at least execute once. That part works now.

However, there’s now a different problem - the collection AllUsers is always empty.

Meteor.users.find().fetch() on the server returns all users.
Meteor.users.find().fetch() on the client returns the currently logged in user.

AllUsers.find().fetch() returns an empty set.

Why not?

There is no collection allUsers, there is only Meteor.users. When you subscribe on the client, check if it returns an error.

I think maybe you are confusing things. Do you believe that Meteor.publish() publishes into a collection? I mean, I guess in a certain way it is, but when you create the collection ‘allUsers’ it references a collection in the database and when you publish ‘allUsers’ it is just a reference to the cursor holding the query you executed.

Okay, I think I got it now. Thanks.