简体   繁体   English

使用Monk在MongoDB中列出集合名称

[英]List Collection Names in MongoDB using Monk

In my Node.js (Express) app that uses Monk, I need to render a list of all collections in the MongoDB database. 在我使用Monk的Node.js(Express)应用程序中,我需要呈现MongoDB数据库中所有集合的列表。

Is there a way to get the list of collections in the database using Monk? 有没有办法使用Monk获取数据库中的集合列表?

This wil basicaly do that, but it takes some digging into the underlying driver to do so: 这将基本上做到这一点,但它需要深入挖掘潜在的驱动程序:

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;
        }))
    }
  )
);

}); });

The driver command is of course "listCollections" and those are the basic hoops you need to jump through to get there 驱动程序命令当然是“listCollections” ,这些是你需要跳过才能到达那里的基本箍

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM