使用Monk在MongoDB中列出集合名称

在使用Monk的Node.js(Express)应用程序中,我需要呈现MongoDB数据库中所有集合的列表。

有没有办法使用Monk来获取数据库中的集合列表?

这样做基本上就是这样做的,但是需要深入挖掘底层驱动程序:

var db = require('monk')('localhost/test'); db.on("open",function() { console.log( db.driver._native.command( { "listCollections": 1 }, function(err,result) { console.log( result.cursor.firstBatch.map(function(el) { return el.name; })) } ) ); 

});

驱动程序的命令当然是“listCollections” ,这些是你需要跳过的基本环节