3

I have a meteor.js application and I would like to take a look at what information is included in all client side collections. There are about 20 client side collections and I know that I can access them one by one and have them return their documents like so:

Meteor.myCollection.find().fetch()

But I'm wondering if there is a way to get all meteor.js collections that are on the client side and loop through them. Can anyone suggest a way to do this?

Stennie
  • 63,885
  • 14
  • 149
  • 175
Abe Miessler
  • 82,532
  • 99
  • 305
  • 486

2 Answers2

3

To get the collection instances:

var collections = _.chain(_.keys(window))
  .filter(function(k) {return window[k] instanceof Meteor.Collection;})
  .map(function(k) {return window[k];})
  .value();

To get the collection names:

var names = _.filter(_.keys(window), function(key) {
  return window[key] instanceof Meteor.Collection;
});
David Weldon
  • 63,632
  • 11
  • 148
  • 146
  • If you want to know which collections have also been populated, you can do `var populated = _.chain(collections).filter(function(cc) { return cc.find().count() > 0; }).map(function(cx) { return { name: cx._name, count: cx.find().count() }; }).value();` – TimDog Apr 20 '16 at 21:04
0

you need this package :-

https://github.com/dburles/mongo-collection-instances

then you can do

Mongo.Collections.getAll()

It gets used in the really useful "Mongol", which allows you to examine your collections / subscriptions on the client side. This tool sounds more like what you are really wanting to achieve

https://github.com/msavin/Mongol

Keith Nicholas
  • 43,549
  • 15
  • 93
  • 156