Is it possible to create new Meteor collections on-the-fly? I'd like to create foo_bar
or bar_bar
depending on some pathname which should be a global variable I suppose (so I can access it throughout my whole application).
Something like:
var prefix = window.location.pathname.replace(/^\/([^\/]*).*$/, '$1');
var Bar = new Meteor.Collection(prefix+'_bar');
The thing here is that I should get my prefix
variable from URL, so if i declare it outside of if (Meteor.isClient)
I get an error: ReferenceError: window is not defined
. Is it possible to do something like that at all?
Edit : Using the first iteration of Akshats answer my project js : http://pastie.org/6411287
I'm not entirely certain this will work:
You need it in two pieces, the first to load collections you've set up before (on both the client and server)
And you need a bit to add the collections on the server:
And you need to create them on the client:
Again, this is all untested so I'm just giving it a shot hopefully it works.
EDIT
Perhaps the below should work, I've added a couple of checks to see if the collection exists first. Please could you run
meteor reset
before you use it to sort bugs from the code above:Also make sure your names are javascript escaped.
Things got much easier:
Run this in your server method.