I already have an established database connection. I need to list the names of the collections in the database. Is it possible?
Asked
Active
Viewed 1,115 times
2 Answers
2
db.collectionNames(function(err, collectionArrayResult) {
//Now do something with collectionArrayResult
});
The result is an array of objects with a 'name' property, like this:
[
{ name: '<dbName>.<collectionName>' },
...
]
Careful though - <dbName>.system.indexes
will be returned too.

UpTheCreek
- 31,444
- 34
- 152
- 221
-
This is the correct answer without using extra packages. If using Meteor by any chance you can get the `db` object from `var db = MongoInternals.defaultRemoteCollectionDriver().mongo.db;` – Davor Lucic Jul 26 '16 at 14:09
-1
To show collections into database from mongo shell :
db.getCollectionNames()
So to show collection in mongoskin try that
var collections = db.collections();
collections.each(function(err, collection) {
console.log(collection);
});
according to this link Mongoskin Tutorial

ahmed hamdy
- 5,096
- 1
- 47
- 58
-
`db` doesn't have a method called `getCollectionNames()`. Try it and your server gets an internal error. – PerakR Feb 04 '14 at 23:40
-
according to db.js https://github.com/christkv/node-mongodb-native/blob/master/lib/mongodb/db.js#L17 – ahmed hamdy Feb 04 '14 at 23:59
-
-
2@PerakR The first line is how you look in the mongo shell. The second section is the code for mongoskin use – Neil Lunn Feb 05 '14 at 03:09
-