summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEliot Horowitz <eliot@10gen.com>2009-02-12 13:47:43 -0500
committerEliot Horowitz <eliot@10gen.com>2009-02-12 13:47:43 -0500
commite13f1df0a1c8b2854082c6059c264aa3414ea402 (patch)
tree272139beb6f3a442ef06c4829d59a8de397d586e
parent23f65c7e871a1edc1014b697c57ad1ad9a6c24a6 (diff)
downloadmongo-e13f1df0a1c8b2854082c6059c264aa3414ea402.tar.gz
mongos: listdatabases command
-rw-r--r--dbgrid/commands.cpp21
1 files 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<DBClientCursor> 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;