I already have an established database connection. I need to list the names of the collections in the database. Is it possible?
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答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
回答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.