2

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

4

2 回答 2

2
db.collectionNames(function(err, collectionArrayResult) {
    //Now do something with collectionArrayResult
});

结果是具有“名称”属性的对象数组,如下所示:

[
   { name: '<dbName>.<collectionName>' },
   ...
]

不过要小心 - <dbName>.system.indexes也会被退回。

于 2015-03-20T12:20:44.210 回答
-1

要将集合从 mongo shell 显示到数据库中:

db.getCollectionNames()

因此,要在 mongoskin 中展示收藏,请尝试

var collections = db.collections();
collections.each(function(err, collection) {
    console.log(collection);
});

根据这个链接Mongoskin Tutorial

于 2014-02-04T23:27:42.237 回答