4

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"...]
2
  • 1
    listCollections returns a MongoCollection which you would iterate over, calling .getNamespace() to get the names. Please note the returned value you are seeing is not JSON but rather the console's interpretation of the object, hence items such as [Function] Commented Jan 1, 2016 at 13:19
  • @PaulS. thanks for clearing this out I will implement code based on this information. Commented Jan 1, 2016 at 13:40

1 Answer 1

8

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 );
  }
});
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.