summaryrefslogtreecommitdiff
path: root/shell
diff options
context:
space:
mode:
authorEliot Horowitz <eliot@10gen.com>2009-08-19 12:10:57 -0400
committerEliot Horowitz <eliot@10gen.com>2009-08-19 12:10:57 -0400
commit61ecff1e953cee8e5d7f4adb4fd59caf9b8f1d1a (patch)
tree30173a26bf01450999e17024db91a762c8d9b4b0 /shell
parent19c885c5a8ff574c5802e0c4d78c2a08ec48434c (diff)
downloadmongo-61ecff1e953cee8e5d7f4adb4fd59caf9b8f1d1a.tar.gz
update visual studio js code
Diffstat (limited to 'shell')
-rw-r--r--shell/mongo_vstudio.cpp212
1 files changed, 167 insertions, 45 deletions
diff --git a/shell/mongo_vstudio.cpp b/shell/mongo_vstudio.cpp
index b69aa2c9612..d38759ab2df 100644
--- a/shell/mongo_vstudio.cpp
+++ b/shell/mongo_vstudio.cpp
@@ -45,9 +45,10 @@ const char * jsconcatcode =
"print(\"\\tdb.foo.getIndexes()\");\n"
"print(\"\\tdb.foo.drop() drop the collection\");\n"
"print(\"\\tdb.foo.validate() - SLOW\");\n"
- "print(\"\\tdb.foo.stats() - stats about the collection - SLOW\");\n"
- "print(\"\\tdb.foo.dataSize() - size in bytes of all the data - SLOW\");\n"
- "print(\"\\tdb.foo.totalIndexSize() - size in bytes of all the indexes - SLOW\");\n"
+ "print(\"\\tdb.foo.stats()\");\n"
+ "print(\"\\tdb.foo.dataSize()\");\n"
+ "print(\"\\tdb.foo.storageSize() - includes free space allocated to this collection\");\n"
+ "print(\"\\tdb.foo.totalIndexSize() - size in bytes of all the indexes\");\n"
"}\n"
"\n"
"DBCollection.prototype.getFullName = function(){\n"
@@ -93,13 +94,24 @@ const char * jsconcatcode =
"throw \"can't save a DBQuery object\";\n"
"}\n"
"\n"
+ "DBCollection._allowedFields = { $id : 1 , $ref : 1 };\n"
+ "\n"
"DBCollection.prototype._validateForStorage = function( o ){\n"
"this._validateObject( o );\n"
"for ( var k in o ){\n"
- "if ( k.indexOf( \".\" ) >= 0 )\n"
+ "if ( k.indexOf( \".\" ) >= 0 ) {\n"
"throw \"can't have . in field names [\" + k + \"]\" ;\n"
"}\n"
+ "\n"
+ "if ( k.indexOf( \"$\" ) == 0 && ! DBCollection._allowedFields[k] ) {\n"
+ "throw \"field names cannot start with $ [\" + k + \"]\";\n"
+ "}\n"
+ "\n"
+ "if ( o[k] !== null && typeof( o[k] ) === \"object\" ) {\n"
+ "this._validateForStorage( o[k] );\n"
+ "}\n"
"}\n"
+ "};\n"
"\n"
"\n"
"DBCollection.prototype.find = function( query , fields , limit , skip ){\n"
@@ -118,10 +130,12 @@ const char * jsconcatcode =
"return ret;\n"
"}\n"
"\n"
- "DBCollection.prototype.insert = function( obj ){\n"
+ "DBCollection.prototype.insert = function( obj , _allow_dot ){\n"
"if ( ! obj )\n"
"throw \"no object!\";\n"
+ "if ( ! _allow_dot ) {\n"
"this._validateForStorage( obj );\n"
+ "}\n"
"return this._mongo.insert( this._fullName , obj );\n"
"}\n"
"\n"
@@ -162,7 +176,7 @@ const char * jsconcatcode =
"\n"
"DBCollection.prototype._indexSpec = function( keys, options ) {\n"
"var name;\n"
- "var unique = false;\n"
+ "var nTrue = 0;\n"
"if ( !isObject( options ) ) {\n"
"options = [ options ];\n"
"}\n"
@@ -171,20 +185,25 @@ const char * jsconcatcode =
"if ( isString( o ) ) {\n"
"name = o;\n"
"} else if ( typeof( o ) == \"boolean\" ) {\n"
- "unique = o;\n"
+ "if ( o ) {\n"
+ "++nTrue;\n"
+ "}\n"
"}\n"
"}\n"
"name = name || this._genIndexName( keys );\n"
"var ret = { ns : this._fullName , key : keys , name : name };\n"
- "if ( unique == true ) {\n"
+ "if ( nTrue > 0 ) {\n"
"ret.unique = true;\n"
"}\n"
+ "if ( nTrue > 1 ) {\n"
+ "ret.dropDups = true;\n"
+ "}\n"
"return ret;\n"
"}\n"
"\n"
"DBCollection.prototype.createIndex = function( keys , options ){\n"
"var o = this._indexSpec( keys, options );\n"
- "this._db.getCollection( \"system.indexes\" ).insert( o );\n"
+ "this._db.getCollection( \"system.indexes\" ).insert( o , true );\n"
"}\n"
"\n"
"DBCollection.prototype.ensureIndex = function( keys , options ){\n"
@@ -195,7 +214,9 @@ const char * jsconcatcode =
"}\n"
"\n"
"this.createIndex( keys , options );\n"
+ "if ( this.getDB().getLastError() == \"\" ) {\n"
"this._indexCache[name] = true;\n"
+ "}\n"
"return true;\n"
"}\n"
"\n"
@@ -328,19 +349,15 @@ const char * jsconcatcode =
"}\n"
"\n"
"DBCollection.prototype.stats = function(){\n"
- "var res = this.validate().result;\n"
- "var p = /\\b(\\w+)\\??: *(\\d+)\\b/g;\n"
- "var m;\n"
- "\n"
- "var o = {};\n"
- "while ( m = p.exec( res ) ){\n"
- "o[ m[1] ] = m[2];\n"
- "}\n"
- "return o;\n"
+ "return this._db.runCommand( { collstats : this._shortName } );\n"
"}\n"
"\n"
"DBCollection.prototype.dataSize = function(){\n"
- "return parseInt( this.stats().datasize );\n"
+ "return this.stats().size;\n"
+ "}\n"
+ "\n"
+ "DBCollection.prototype.storageSize = function(){\n"
+ "return this.stats().storageSize;\n"
"}\n"
"\n"
"DBCollection.prototype.totalIndexSize = function(){\n"
@@ -378,6 +395,11 @@ const char * jsconcatcode =
"return this._db.group( params );\n"
"}\n"
"\n"
+ "DBCollection.prototype.groupcmd = function( params ){\n"
+ "params.ns = this._shortName;\n"
+ "return this._db.groupcmd( params );\n"
+ "}\n"
+ "\n"
"DBCollection.prototype.toString = function(){\n"
"return this.getFullName();\n"
"}\n"
@@ -429,6 +451,12 @@ const char * jsconcatcode =
"\n"
"DB.prototype._dbCommand = DB.prototype.runCommand;\n"
"\n"
+ "DB.prototype._adminCommand = function( obj ){\n"
+ "if ( this._name == \"admin\" )\n"
+ "return this.runCommand( obj );\n"
+ "return this.getSisterDB( \"admin\" ).runCommand( obj );\n"
+ "}\n"
+ "\n"
"DB.prototype.addUser = function( username , pass ){\n"
"var c = this.getCollection( \"system.users\" );\n"
"\n"
@@ -508,13 +536,16 @@ const char * jsconcatcode =
"* @return Object returned has member ok set to true if operation succeeds, false otherwise.\n"
"*/\n"
"DB.prototype.dropDatabase = function() {\n"
+ "if ( arguments.length )\n"
+ "throw \"dropDatabase doesn't take arguments\";\n"
"return this._dbCommand( { dropDatabase: 1 } );\n"
"}\n"
"\n"
"\n"
"DB.prototype.shutdownServer = function() {\n"
- "if( \"admin\" != db )\n"
+ "if( \"admin\" != this._name ){\n"
"return \"shutdown command only works with the admin database; try 'use admin'\";\n"
+ "}\n"
"\n"
"try {\n"
"this._dbCommand(\"shutdown\");\n"
@@ -600,7 +631,7 @@ const char * jsconcatcode =
"assert( isString(todb) && todb.length );\n"
"fromhost = fromhost || \"\";\n"
"\n"
- "return this._dbCommand( { copydb:1, fromhost:fromhost, fromdb:fromdb, todb:todb } );\n"
+ "return this._adminCommand( { copydb:1, fromhost:fromhost, fromdb:fromdb, todb:todb } );\n"
"}\n"
"\n"
"/**\n"
@@ -617,6 +648,7 @@ const char * jsconcatcode =
"print(\"DB methods:\");\n"
"print(\"\\tdb.auth(username, password)\");\n"
"print(\"\\tdb.getMongo() get the server connection object\");\n"
+ "print(\"\\tdb.getMongo().setSlaveOk() allow this connection to read from the nonmaster member of a replica pair\");\n"
"print(\"\\tdb.getSisterDB(name) get the db at the same server as this onew\");\n"
"print(\"\\tdb.getName()\");\n"
"print(\"\\tdb.getCollection(cname) same as db['cname'] or db.cname\");\n"
@@ -639,6 +671,9 @@ const char * jsconcatcode =
"print(\"\\tdb.resetError()\");\n"
"print(\"\\tdb.getCollectionNames()\");\n"
"print(\"\\tdb.group(ns, key[, keyf], cond, reduce, initial)\");\n"
+ "print(\"\\tdb.currentOp() displays the current operation in the db\" );\n"
+ "print(\"\\tdb.killOp() kills the current operation in the db\" );\n"
+ "print(\"\\tdb.version() current version of the server\" );\n"
"}\n"
"\n"
"/**\n"
@@ -748,17 +783,22 @@ const char * jsconcatcode =
"var parms = args[0];\n"
"var c = db[parms.ns].find(parms.cond||{});\n"
"var map = new Map();\n"
+ "var pks = parms.key ? parms.key.keySet() : null;\n"
+ "var pkl = pks ? pks.length : 0;\n"
+ "var key = {};\n"
"\n"
"while( c.hasNext() ) {\n"
"var obj = c.next();\n"
- "var key = {};\n"
- "if( parms.key ) {\n"
- "for( var i in parms.key )\n"
- "key[i] = obj[i];\n"
+ "if ( pks ) {\n"
+ "for( var i=0; i<pkl; i++ ){\n"
+ "var k = pks[i];\n"
+ "key[k] = obj[k];\n"
+ "}\n"
"}\n"
"else {\n"
"key = parms.$keyf(obj);\n"
"}\n"
+ "\n"
"var aggObj = map.get(key);\n"
"if( aggObj == null ) {\n"
"var newObj = Object.extend({}, key); \n"
@@ -771,6 +811,18 @@ const char * jsconcatcode =
"return map.values();\n"
"}\n"
"\n"
+ "return this.eval(groupFunction, this._groupFixParms( parmsObj ));\n"
+ "}\n"
+ "\n"
+ "DB.prototype.groupcmd = function( parmsObj ){\n"
+ "var ret = this.runCommand( { \"group\" : this._groupFixParms( parmsObj ) } );\n"
+ "if ( ! ret.ok ){\n"
+ "throw \"group command failed: \" + tojson( ret );\n"
+ "}\n"
+ "return ret.retval;\n"
+ "}\n"
+ "\n"
+ "DB.prototype._groupFixParms = function( parmsObj ){\n"
"var parms = Object.extend({}, parmsObj);\n"
"\n"
"if( parms.reduce ) {\n"
@@ -783,7 +835,7 @@ const char * jsconcatcode =
"delete parms.keyf;\n"
"}\n"
"\n"
- "return this.eval(groupFunction, parms);\n"
+ "return parms;\n"
"}\n"
"\n"
"DB.prototype.resetError = function(){\n"
@@ -905,6 +957,14 @@ const char * jsconcatcode =
"\n"
"return result;\n"
"}\n"
+ "\n"
+ "DB.prototype.serverBuildInfo = function(){\n"
+ "return this._adminCommand( \"buildinfo\" );\n"
+ "}\n"
+ "\n"
+ "DB.prototype.version = function(){\n"
+ "return this.serverBuildInfo().version;\n"
+ "}\n"
"/**\n"
"* Copyright (C) 2008 10gen Inc.\n"
"*\n"
@@ -1453,6 +1513,12 @@ const char * jsconcatcode =
"return n.next();\n"
"}\n"
"\n"
+ "DBQuery.prototype.snapshot = function(){\n"
+ "this._ensureSpecial();\n"
+ "this._query.$snapshot = true;\n"
+ "return this;\n"
+ "}\n"
+ "\n"
"DBQuery.prototype.shellPrint = function(){\n"
"try {\n"
"var n = 0;\n"
@@ -1519,6 +1585,7 @@ const char * jsconcatcode =
"}\n"
"else {\n"
"fullArgs.push( \"--\" + k );\n"
+ "if ( o[k] != \"\" )\n"
"fullArgs.push( \"\" + o[k] );\n"
"}\n"
"}\n"
@@ -1566,7 +1633,7 @@ const char * jsconcatcode =
"} catch( e ) {\n"
"}\n"
"return false;\n"
- "}, \"unable to connect to mongo program on port \" + port, 10000 );\n"
+ "}, \"unable to connect to mongo program on port \" + port, 30000 );\n"
"\n"
"return m;\n"
"}\n"
@@ -1591,7 +1658,7 @@ const char * jsconcatcode =
"this._serverNames = [];\n"
"\n"
"for ( var i=0; i<numServers; i++){\n"
- "var conn = startMongod( { port : 30000 + i , dbpath : \"/data/db/\" + testName + i } );\n"
+ "var conn = startMongod( { port : 30000 + i , dbpath : \"/data/db/\" + testName + i , noprealloc : \"\" } );\n"
"conn.name = \"localhost:\" + ( 30000 + i );\n"
"\n"
"this._connections.push( conn );\n"
@@ -1686,12 +1753,14 @@ const char * jsconcatcode =
"if ( this.peer_ && this.arbiter_ ) {\n"
"args.push( \"--pairwith\" );\n"
"args.push( this.peer_ );\n"
+ "args.push( \"--arbiter\" );\n"
"args.push( this.arbiter_ );\n"
"args.push( \"--oplogSize\" );\n"
"\n"
"args.push( \"1\" );\n"
"}\n"
"args.push( \"--nohttpinterface\" );\n"
+ "args.push( \"--noprealloc\" );\n"
"args.push( \"--bind_ip\" );\n"
"args.push( \"127.0.0.1\" );\n"
"if ( this.extraArgs_ ) {\n"
@@ -1861,11 +1930,16 @@ const char * jsconcatcode =
"}\n"
"\n"
"\n"
+ "doassert = function( msg ){\n"
+ "print( \"assert: \" + msg );\n"
+ "throw msg;\n"
+ "}\n"
+ "\n"
"assert = function( b , msg ){\n"
"if ( b )\n"
"return;\n"
"\n"
- "throw \"assert failed : \" + msg;\n"
+ "doassert( \"assert failed : \" + msg );\n"
"}\n"
"\n"
"assert.eq = function( a , b , msg ){\n"
@@ -1875,14 +1949,14 @@ const char * jsconcatcode =
"if ( ( a != null && b != null ) && friendlyEqual( a , b ) )\n"
"return;\n"
"\n"
- "throw \"[\" + tojson( a ) + \"] != [\" + tojson( b ) + \"] are not equal : \" + msg;\n"
+ "doassert( \"[\" + tojson( a ) + \"] != [\" + tojson( b ) + \"] are not equal : \" + msg );\n"
"}\n"
"\n"
"assert.neq = function( a , b , msg ){\n"
"if ( a != b )\n"
"return;\n"
"\n"
- "throw \"[\" + a + \"] != [\" + b + \"] are equal : \" + msg;\n"
+ "doassert( \"[\" + a + \"] != [\" + b + \"] are equal : \" + msg );\n"
"}\n"
"\n"
"assert.soon = function( f, msg, timeout, interval ) {\n"
@@ -1894,7 +1968,7 @@ const char * jsconcatcode =
"if ( f() )\n"
"return;\n"
"if ( ( new Date() ).getTime() - start.getTime() > timeout )\n"
- "throw \"assert.soon failed: \" + f + \", msg:\" + msg;\n"
+ "doassert( \"assert.soon failed: \" + f + \", msg:\" + msg );\n"
"sleep( interval );\n"
"}\n"
"}\n"
@@ -1908,40 +1982,40 @@ const char * jsconcatcode =
"return e;\n"
"}\n"
"\n"
- "throw \"did not throw exception: \" + msg ;\n"
+ "doassert( \"did not throw exception: \" + msg );\n"
"}\n"
"\n"
"assert.commandWorked = function( res , msg ){\n"
"if ( res.ok == 1 )\n"
"return;\n"
"\n"
- "throw \"command failed: \" + tojson( res ) + \" : \" + msg;\n"
+ "doassert( \"command failed: \" + tojson( res ) + \" : \" + msg );\n"
"}\n"
"\n"
"assert.commandFailed = function( res , msg ){\n"
"if ( res.ok == 0 )\n"
"return;\n"
"\n"
- "throw \"command worked when it should have failed: \" + tojson( res ) + \" : \" + msg;\n"
+ "doassert( \"command worked when it should have failed: \" + tojson( res ) + \" : \" + msg );\n"
"}\n"
"\n"
"assert.isnull = function( what , msg ){\n"
"if ( what == null )\n"
"return;\n"
"\n"
- "throw \"supposed to null (\" + ( msg || \"\" ) + \") was: \" + tojson( what );\n"
+ "doassert( \"supposed to null (\" + ( msg || \"\" ) + \") was: \" + tojson( what ) );\n"
"}\n"
"\n"
"assert.lt = function( a , b , msg ){\n"
"if ( a < b )\n"
"return;\n"
- "throw a + \" is not less than \" + b + \" : \" + msg;\n"
+ "doassert( a + \" is not less than \" + b + \" : \" + msg );\n"
"}\n"
"\n"
"assert.gt = function( a , b , msg ){\n"
"if ( a > b )\n"
"return;\n"
- "throw a + \" is not greater than \" + b + \" : \" + msg;\n"
+ "doassert( a + \" is not greater than \" + b + \" : \" + msg );\n"
"}\n"
"\n"
"Object.extend = function( dst , src ){\n"
@@ -2107,6 +2181,11 @@ const char * jsconcatcode =
"if ( typeof( x.tojson ) == \"function\" && x.tojson != tojson )\n"
"return x.tojson();\n"
"\n"
+ "if ( x.toString() == \"[object MaxKey]\" )\n"
+ "return \"{ $maxKey : 1 }\";\n"
+ "if ( x.toString() == \"[object MinKey]\" )\n"
+ "return \"{ $minKey : 1 }\";\n"
+ "\n"
"var s = \"{\";\n"
"\n"
"var first = true;\n"
@@ -2148,8 +2227,16 @@ const char * jsconcatcode =
"\n"
"shellPrintHelper = function( x ){\n"
"\n"
- "if ( typeof( x ) == \"undefined\" )\n"
+ "if ( typeof( x ) == \"undefined\" ){\n"
+ "\n"
+ "if ( typeof( db ) != \"undefined\" && db.getLastError ){\n"
+ "var e = db.getLastError();\n"
+ "if ( e != null )\n"
+ "print( e );\n"
+ "}\n"
+ "\n"
"return;\n"
+ "}\n"
"\n"
"if ( x == null ){\n"
"print( \"null\" );\n"
@@ -2185,6 +2272,8 @@ const char * jsconcatcode =
"}\n"
"\n"
"help = shellHelper.help = function(){\n"
+ "if ( typeof( db ) != \"undefined\" )\n"
+ "print( \"server version: \" + db.version() );\n"
"print( \"HELP\" );\n"
"print( \"\\t\" + \"show dbs show database names\");\n"
"print( \"\\t\" + \"show collections show collections in current database\");\n"
@@ -2248,8 +2337,29 @@ const char * jsconcatcode =
"\n"
"if ( typeof( Map ) == \"undefined\" ){\n"
"Map = function(){\n"
- "this._data = [];\n"
+ "this._data = {};\n"
+ "}\n"
+ "}\n"
+ "\n"
+ "Map.hash = function( val ){\n"
+ "if ( ! val )\n"
+ "return val;\n"
+ "\n"
+ "switch ( typeof( val ) ){\n"
+ "case 'string':\n"
+ "case 'number':\n"
+ "case 'date':\n"
+ "return val.toString();\n"
+ "case 'object':\n"
+ "case 'array':\n"
+ "var s = \"\";\n"
+ "for ( var k in val ){\n"
+ "s += k + val[k];\n"
+ "}\n"
+ "return s;\n"
"}\n"
+ "\n"
+ "throw \"can't hash : \" + typeof( val );\n"
"}\n"
"\n"
"Map.prototype.put = function( key , value ){\n"
@@ -2264,18 +2374,29 @@ const char * jsconcatcode =
"}\n"
"\n"
"Map.prototype._get = function( key ){\n"
- "for ( var i=0; i<this._data.length; i++ ){\n"
- "if ( friendlyEqual( key , this._data[i].key ) ){\n"
- "return this._data[i];\n"
+ "var h = Map.hash( key );\n"
+ "var a = this._data[h];\n"
+ "if ( ! a ){\n"
+ "a = [];\n"
+ "this._data[h] = a;\n"
+ "}\n"
+ "\n"
+ "for ( var i=0; i<a.length; i++ ){\n"
+ "if ( friendlyEqual( key , a[i].key ) ){\n"
+ "return a[i];\n"
"}\n"
"}\n"
"var o = { key : key , value : null };\n"
- "this._data.push( o );\n"
+ "a.push( o );\n"
"return o;\n"
"}\n"
"\n"
"Map.prototype.values = function(){\n"
- "return this._data.map( function(z){ return z.value } );\n"
+ "var all = [];\n"
+ "for ( var k in this._data ){\n"
+ "this._data[k].forEach( function(z){ all.push( z.value ); } );\n"
+ "}\n"
+ "return all;\n"
"}\n"
"\n"
"Math.sigFig = function( x , N ){\n"
@@ -2285,5 +2406,6 @@ const char * jsconcatcode =
"var p = Math.pow( 10, N - Math.ceil( Math.log( Math.abs(x) ) / Math.log( 10 )) );\n"
"return Math.round(x*p)/p;\n"
"}\n"
+ "\n"
;