List of collection names in MongoDB using Monk

In my Node.js (Express) application using Monk, I need to display a list of all collections in a MongoDB database.

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

+3


source to share


1 answer


This will usually do it, but it requires some digging into the underlying driver:

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 these are the main hoops to jump over to get there

+1


source







All Articles