3

In my Node.js (Express) app that uses Monk, I need to render a list of all collections in the MongoDB database.

Is there a way to get the list of collections in the database using Monk?

4

1 回答 1

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”,这些是您需要跳过的基本步骤才能到达那里

于 2015-06-28T17:28:47.950 回答