Is there a way to list collections with mongoskin?

2019-05-22 12:27发布

I already have an established database connection. I need to list the names of the collections in the database. Is it possible?

2条回答
孤傲高冷的网名
2楼-- · 2019-05-22 12:54

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

查看更多
【Aperson】
3楼-- · 2019-05-22 13:16
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.

查看更多
登录 后发表回答