Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get Meteor collection by name

Tags:

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.

like image 504
Trevor Burnham Avatar asked Jun 11 '12 16:06

Trevor Burnham


1 Answers

Based on Shane Donelley's mongoinspector https://github.com/shanedonnelly1/mongoinspector

getCollection = function (string) { for (var globalObject in window) {     if (window[globalObject] instanceof Meteor.Collection) {         if (globalObject === string) {             return (window[globalObject]);             break;         };             } } return undefined; // if none of the collections match }; 
like image 168
user2014160 Avatar answered Sep 17 '22 18:09

user2014160