在我使用Monk的Node.js (Express)应用程序中,我需要呈现MongoDB数据库中所有集合的列表。
是否有方法使用Monk获取数据库中的集合列表?
发布于 2015-06-28 17:28:47
这将基本做到这一点,但需要对底层驱动程序进行深入研究:
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",这是您需要跳过去才能到达的基本循环。
https://stackoverflow.com/questions/31102049
复制相似问题