From e13f1df0a1c8b2854082c6059c264aa3414ea402 Mon Sep 17 00:00:00 2001 From: Eliot Horowitz Date: Thu, 12 Feb 2009 13:47:43 -0500 Subject: [PATCH] mongos: listdatabases command --- dbgrid/commands.cpp | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/dbgrid/commands.cpp b/dbgrid/commands.cpp index 2beaf0679b4..b9236c8165d 100644 --- a/dbgrid/commands.cpp +++ b/dbgrid/commands.cpp @@ -74,9 +74,24 @@ namespace mongo { public: ListDatabaseCommand() : GridAdminCmd("listdatabases") { } bool run(const char *ns, BSONObj& cmdObj, string& errmsg, BSONObjBuilder& result, bool){ - // TODO - result.append("not done", 1); - return false; + ScopedDbConnection conn( configServer.getPrimary() ); + + + auto_ptr cursor = conn->query( "config.databases" , emptyObj ); + + BSONObjBuilder list; + int num = 0; + while ( cursor->more() ){ + string s = BSONObjBuilder::numStr( num++ ); + + BSONObj o = cursor->next(); + list.append( s.c_str() , o["name"].valuestrsafe() ); + } + + result.appendArray("databases" , list.obj() ); + conn.done(); + + return true; } } gridListDatabase;