1

The goal is to get a list of all the collections in the database using mongoskin.

I know you can enter the db.getCollectionNames() method in mongo shell to do this, but I haven't found a way to achieve the same in my app.

I have already looked at a similar post on SO (Is there a way to list collections with mongoskin?) and tried the posted solution without success.

Community
  • 1
  • 1
jeebface
  • 841
  • 1
  • 12
  • 29

1 Answers1

-1

It's collectionNames(). It returns databasename.collectionname (ex. "test.user") though... but you can do some string manipulations to get rid of that if you need.

db.collectionNames(function(err, items) {
  items.forEach(function(item) {
    console.log(item.name);
  });
});
Ben
  • 5,024
  • 2
  • 18
  • 23
  • my hero. just wondering, is db.collectionNames a default mongo method or a mongoskin specific one? – jeebface Jul 18 '14 at 18:26
  • 1
    it's from mongo-native driver http://mongodb.github.io/node-mongodb-native/api-generated/db.html#collectionnames. Mongoskin is based on mongo-native so if you can't find what you need in mongoskin doc [not surprised :)], look in mongo-native doc. – Ben Jul 18 '14 at 18:37