Permalink
Browse files

sharding helper

  • Loading branch information...
1 parent 90372ab commit bf09b1cc49bb2bff684dff1bf97043063d764016 @erh erh committed Apr 15, 2011
Showing with 37 additions and 0 deletions.
  1. +37 −0 shell/utils_sh.js
View
@@ -0,0 +1,37 @@
+sh = function() { return "try sh.help();" }
+
+
+sh._checkMongos = function() {
+ var x = db.runCommand( "ismaster" );
+ if ( x.msg != "isdbgrid" )
+ throw "not connected to a mongos"
+}
+
+sh._adminCommand = function( cmd ) {
+ sh._checkMongos();
+ var res = db.getSisterDB( "admin" ).runCommand( cmd );
+
+ if ( res == null || ! res.ok ) {
+ print( "command failed: " + tojson( res ) )
+ }
+
+ return res;
+}
+
+sh.help = function() {
+ print( "\tsh.enableSharding(dbname) enables sharding on the database dbname" )
+ print( "\tsh.status() prints a general overview of the cluster" )
+}
+
+sh.status = function( verbose , configDB ) {
+ // TODO: move the actual commadn here
+ printShardingStatus( configDB , verbose );
+}
+
+sh.enableSharding = function( dbname ) {
+ assert( dbname , "need a valid dbname" )
+ sh._adminCommand( { enableSharding : dbname } )
+}
+
+
+

0 comments on commit bf09b1c

Please sign in to comment.