Dariusz Sikorski
Dariusz Sikorski

Reputation: 4407

How to retrieve all Meteor Mongo collection names as Javascript array?

I tried to use:

MongoInternals.defaultRemoteCollectionDriver().mongo.db.listCollections()

in order to get all collection names in meteor database, but it returns a very long JSON, in which i couldn't find the pure collection names. (see the attached image)

enter image description here

How can I get meteor collection names in a following format:

["test1", "test2", "users"...]

Upvotes: 4

Views: 1135

Answers (1)

Dariusz Sikorski
Dariusz Sikorski

Reputation: 4407

Ok, here is the working code, thanks @PaulS.

db = MongoInternals.defaultRemoteCollectionDriver().mongo.db;
collections = db.listCollections();

collections.each(function(n, collection){
  if(collection){
    console.log( collection.name );
  }
});

Upvotes: 8

Related Questions