【问题标题】:List Collection Names in MongoDB using Monk使用 Monk 在 MongoDB 中列出集合名称
【发布时间】:2015-06-28 16:25:29
【问题描述】:

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

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

【问题讨论】:

    标签: node.js mongodb express monk


    【解决方案1】:

    这将基本上做到这一点,但需要深入挖掘底层驱动程序才能做到这一点:

    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",这些是您需要跳过的基本步骤

    【讨论】:

      猜你喜欢
      • 2014-09-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-07-29
      • 1970-01-01
      相关资源
      最近更新 更多