How do I use a dynamic variable as a Meteor/MongoDB collection name? -


so tried didn't work (on isserver) :

var tablename= ""; (...) if (silly_cond === 1){     tablename = "table1"; }else{     tablename = "table2"; } tablecol = new mongo.collection(tablename); 

for reason can't work. seems accept

tablecol = new mongo.collection("table1"); 

the idea fetch tablename table id, , apply same js different tables (on different templates). doing wrong?

you need declare tablename outside functions, otherwise can't seen.

var tablename = ""; if (silly_cond === 1){     tablename = "table1"; }else{     tablename = "table2"; } tablecol = new mongo.collection(tablename); 

Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -