【发布时间】:2015-06-28 16:25:29
【问题描述】:
在我使用 Monk 的 Node.js (Express) 应用程序中,我需要呈现 MongoDB 数据库中所有集合的列表。
有没有办法使用 Monk 获取数据库中的集合列表?
【问题讨论】:
标签: node.js mongodb express monk
在我使用 Monk 的 Node.js (Express) 应用程序中,我需要呈现 MongoDB 数据库中所有集合的列表。
有没有办法使用 Monk 获取数据库中的集合列表?
【问题讨论】:
标签: node.js mongodb express 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",这些是您需要跳过的基本步骤
【讨论】: