0

i defined a array "userCollections" without var in my lib folder, fill this with new Collections:

userCollections = [];
Collectionlist = CustomCollections.find({});
Collectionlist.forEach(function(col) {
   userCollections[col.name] = new Meteor.Collection(col.name);

   Meteor.publish(col.name, function(){
     return Mongo.Collection.get(col.name).find({});
   });
     console.log(userCollections[col.name]);
});

But in my client Folder my array is empty.

console.log(userCollections);

Why?


The Problem is:

userCollections = [];
userCollections["0"] = "0_test";

Collectionlist = CustomCollections.find({});
Collectionlist.forEach(function(col) {
   userCollections["1"] = "1_test";
   console.log(userCollections); //---->  array -> "1":"1_test"
});

in my CollectionCursor-forEach and in my server folder the array is defined

console.log(userCollections); //---->  array -> "0":"0_test"

but outside my forEach and in the client folder the array is undefined... There is a scope problem?

  • You have to subscribe client on those channels. – Marius Darila Mar 20 '15 at 16:58
  • What i should subscribe? my array -> userCollections ? – andreasloskan Mar 23 '15 at 09:49
  • I think you dont understand how subscription works on client. You cant use ```CustomCollections.find({})``` on client if you dont have a subscription for that collection. run ```meteor add autopublish``` to see if it works, this is just for testing purpose. Read this http://stackoverflow.com/questions/19826804/understanding-meteor-publish-subscribe – Marius Darila Mar 23 '15 at 10:02
  • hmm okay, but CustomCollections.find({}) is in my lib folder -> the Collectionlist is not empty. i published and subcribe the CustomCollections. I will test it with meteor add autopublish – andreasloskan Mar 23 '15 at 10:19
  • whit `meteor add autopublish` is the same...my array `userCollections` have the old set value `"0_test"` and not the new set value in the forEach `"1_test"` – andreasloskan Mar 23 '15 at 10:29
  • The code under lib folder is ran both on client and server. You cant publish on client if you understand. Please separte the logic to ```server``` and ```client```. Put publications under server/publications and subs only under client folder or at least use ```if (Meteor.isServer) {//YOUR PUBLISH}``` – Marius Darila Mar 23 '15 at 10:45
  • i have published the the collection under server/publications.js `Meteor.publish('customcollections', function() { return CustomCollections.find(); });` in my client folder i subcribe with the iron route this collection... – andreasloskan Mar 23 '15 at 11:19

0 Answers0