meteor

Get Meteor collection by name


Suppose I write:

new Meteor.Collection("foos");
new Meteor.Collection("bars");

Is there an API for accessing those collections by name? Something like Meteor.Collection.get(name), where name is "foos" or "bars"? I know I could write something like

var MyCollections = {
    foos: new Meteor.Collection("foos");
    bars: new Meteor.Collection("bars");
}

and then use MyCollections[name], but I'd prefer to use an existing API if one exists.


Solution

  • As far as I can see in the collection.js source there currently is no way in the api to get an existing Collection by name, once it has already been initialized on the server. It probably wouldn't be hard to add that feature.

    So, why not fork Meteor and submit a patch or create a smart package and share it I'm sure there are others out there who'd like the same feature.