0

I try to do a admin panel in SailsJS and i want show in a view all collections in a mongo database selected in connection.js but i dont know to do that.

Can i create a model without waterline and require mongoose in a model for this purpose???

Thanks

Travis Webb
  • 14,688
  • 7
  • 55
  • 109

1 Answers1

0

I create a service that i can use around the app, and in this service i created a file Collection.js

var mongoose = require("mongoose");
mongoose.connect( 'mongodb://localhost/admin' );
module.exports = {
  list: function(cb){
    mongoose.connection.db.collectionNames(function (err, names) {
      console.log(names); // [{ name: 'dbname.myCollection' }]
      cb(names)
    });
  }

}

And i call in a controller like

Controller.list(function(names){
 //retrieve all names of collections in database mongo in names
}