Collections in client are not defined

Why are mine collections undefined when I’m using the pub/sub model to get collections:

On my server.js file:

images = new Mongo.Collection("images");
images.deny({
    insert() { return true; },
    update() { return true; },
    remove() { return true; }
});

Meteor.publish("images", function (limit) {
    if (this.userId) {
        return images.find({user:{$ne:this.userId}}, {sort:{createdAt:-1}},{limit:limit});
    }else{
        this.ready();
    }
});

On my client.js file:

var handle;
Deps.autorun(function(){
    handle = Meteor.subscribeWithPagination("images", 2);
});

Template.myHome.helpers({
    userImgs: function(){

        var userID = Meteor.user()._id;

        usersImages = new ReactiveVar(images.find({_id:{$ne: userID}},{ImagesUploaded: {$elemMatch: {editStatus:true}}}).fetch());
}
});

This gives me the error on my client:

Exception in template helper: ReferenceError: images is not defined

Why does it give this error?

Thanks

1 Like

You’ve defined your images collection in your server.js file, which I’m assuming (without seeing more of your code) you are only calling server side (under a server/ directory somewhere). This means the client side has no knowledge of your images collection. You’ll want to define your collection in a client/server shared location, instead of only making it available on one side. For example (I’m assuming your aren’t using Meteor 1.3’s new ES2015 module support based on your examples), you could define your collection in a location like /lib/collection.js, which would be used by both client/server. Take a look at the Special directories and Files outside special directories sections of the Guide for more info.

Thanks

That was the issue of only having it defined in the server.