node.js - 使用 Monk 列出 MongoDB 中的集合名称

标签 node.js mongodb express monk

在我使用 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/

相关文章:

mongodb - $concat mongodb 中的两个字段

mongodb - 无法通过 _id 在 mongoDB 中找到记录

javascript - 类型错误 : 'undefined' is not a function when using mongoDB sort operator

node.js - NODEJS + WS 库 = 缓冲区分配错误

node.js - 如何从express-stormpath库中自定义注销的redirectURL?

javascript - Express Router 中间件错误 (`app.use() requires a middleware function` )

javascript - 带有 Sequelize 的 Node.js 上的 SQL Server 2008

javascript - 使用变量传递回调

javascript - 无法运行本地主机:3000 on meanstack MEANIO, https ://github. com/linnovate/mean

Node.js 中带有相对路径的 java 命令