Skip to content

Instantly share code, notes, and snippets.

@edwardhotchkiss
Created May 25, 2012 02:48
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save edwardhotchkiss/2785463 to your computer and use it in GitHub Desktop.
Save edwardhotchkiss/2785463 to your computer and use it in GitHub Desktop.
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