Is there a way to list collections with mongoskin?

我怕爱的太早我们不能终老 提交于 2019-12-07 21:41:58

问题


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.



来源:https://stackoverflow.com/questions/21565191/is-there-a-way-to-list-collections-with-mongoskin

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!