Skip to content

@edwardhotchkiss /action.js
Created

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
node.js list all mongodb databases
/**
* Uses MongooseJS to Connect to MongoDB
* .Maps out all collections within
*/
var mongoose = require('mongoose')
, MONGO_DB = 'mongodb://localhost/test';
mongoose.connect(MONGO_DB);
mongoose.connection.on('open', function(){
mongoose.connection.db.collectionNames(function(error, names) {
if (error) {
throw new Error(error);
} else {
names.map(function(name) {
console.log('found collection %s', name);
});
}
});
});
mongoose.connection.on('error', function(error){
throw new Error(error);
});
/* EOF */
$ node script.js
$ npm install mongoose
var mongoose = require('mongoose')
, dbNative = mongoose.connection.db;
console.log(dbNative);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.