The Author Online Book Forums are Moving

The Author Online Book Forums will soon redirect to Manning's liveBook and liveVideo. All book forum content will migrate to liveBook's discussion forum and all video forum content will migrate to liveVideo. Log in to liveBook or liveVideo with your Manning credentials to join the discussion!

Thank you for your engagement in the AoF over the years! We look forward to offering you a more enhanced forum experience.

398609 (5) [Avatar] Offline
#1
I am building a mongo client using nw.js and native nodejs mongodb driver .
I have managed to get all the databases in the server using listDatabases function, But I can't get collections for the databases. I know this is because I have mentioned 'test' at the time of connection.
Is there any way to get all the databases and all the collections like in robomongo or mongochef.?

My code :

var host = 'localhost';
var port = 27017;

function connectToMongoServer(host,port,cb) {
	
	dbHandle = new Db('test', new Server(host, port));
	// Establish connection to db
	dbHandle.open(function(err, db) {	

   	//Use the admin database for the operation
   	var adminDb = dbHandle.admin();
   	updateCurrentFolder(host);
	  List all the available databases
	  adminDb.listDatabases(function(err, dbs) {
	    assert.equal(null, err);
	    assert.ok(dbs.databases.length > 0);
	    	async.map(dbs.databases,function(db,internalcb){
	    		populateDBWithCollections(db,internalcb);
	    	},cb)
		});
	  

	});
}


function populateDBWithCollections(db,cb) {
 		var result;
 		db.collections(function(err,items){
 			assert.ok(items.length > 0);
 			result = {name:'',collections:items};
 			cb(err,result);
 		});
}


But db.collections function doesn't exist . Is there any alternative way ?