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
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
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.