在我使用 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"这些是您到达那里需要跳过的基本环节
关于node.js - 使用 Monk 列出 MongoDB 中的集合名称,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31102049/