0
0
mirror of https://github.com/mongodb/mongo.git synced 2024-11-30 17:10:48 +01:00

update vstudio js code

This commit is contained in:
Eliot Horowitz 2009-06-08 10:57:35 -04:00
parent 2536e9eae0
commit f17f26a629

View File

@ -44,7 +44,10 @@ const char * jsconcatcode =
"print(\"\\tdb.foo.dropIndex(name)\");\n"
"print(\"\\tdb.foo.getIndexes()\");\n"
"print(\"\\tdb.foo.drop() drop the collection\");\n"
"print(\"\\tdb.foo.validate()\");\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"
"}\n"
"\n"
"DBCollection.prototype.getFullName = function(){\n"
@ -97,7 +100,7 @@ const char * jsconcatcode =
"}\n"
"\n"
"DBCollection.prototype.findOne = function( query , fields ){\n"
"var cursor = this._mongo.find( this._fullName , this._massageObject( query ) || {} , fields , 1 , 0 );\n"
"var cursor = this._mongo.find( this._fullName , this._massageObject( query ) || {} , fields , -1 , 0 );\n"
"if ( ! cursor.hasNext() )\n"
"return null;\n"
"var ret = cursor.next();\n"
@ -125,7 +128,8 @@ const char * jsconcatcode =
"}\n"
"\n"
"DBCollection.prototype.save = function( obj ){\n"
"if ( ! obj._id ){\n"
"if ( typeof( obj._id ) == \"undefined\" ){\n"
"obj._id = new ObjectId();\n"
"return this.insert( obj );\n"
"}\n"
"else {\n"
@ -177,8 +181,9 @@ const char * jsconcatcode =
"DBCollection.prototype.ensureIndex = function( keys , options ){\n"
"var name = this._indexSpec( keys, options ).name;\n"
"this._indexCache = this._indexCache || {};\n"
"if ( this._indexCache[ name ] )\n"
"if ( this._indexCache[ name ] ){\n"
"return false;\n"
"}\n"
"\n"
"this.createIndex( keys , options );\n"
"this._indexCache[name] = true;\n"
@ -237,20 +242,23 @@ const char * jsconcatcode =
"}\n"
"\n"
"DBCollection.prototype.getIndexes = function(){\n"
"return this.getDB().getCollection( \"system.indexes\" ).find( { ns : this.getFullName() } );\n"
"return this.getDB().getCollection( \"system.indexes\" ).find( { ns : this.getFullName() } ).toArray();\n"
"}\n"
"\n"
"DBCollection.prototype.getIndexSpecs = function(){\n"
"return this.getIndexes().toArray().map(\n"
"DBCollection.prototype.getIndices = DBCollection.prototype.getIndexes;\n"
"DBCollection.prototype.getIndexSpecs = DBCollection.prototype.getIndexes;\n"
"\n"
"DBCollection.prototype.getIndexKeys = function(){\n"
"return this.getIndexes().map(\n"
"function(i){\n"
"return i;\n"
"return i.key;\n"
"}\n"
");\n"
"}\n"
"\n"
"\n"
"DBCollection.prototype.count = function(){\n"
"return this.find().count();\n"
"DBCollection.prototype.count = function( x ){\n"
"return this.find( x ).count();\n"
"}\n"
"\n"
"/**\n"
@ -310,10 +318,65 @@ const char * jsconcatcode =
"return this._db.getCollection( this._shortName + \".\" + subName );\n"
"}\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"
"}\n"
"\n"
"DBCollection.prototype.dataSize = function(){\n"
"return parseInt( this.stats().datasize );\n"
"}\n"
"\n"
"DBCollection.prototype.totalIndexSize = function(){\n"
"var total = 0;\n"
"var mydb = this._db;\n"
"var shortName = this._shortName;\n"
"this.getIndexes().forEach(\n"
"function( spec ){\n"
"var coll = mydb.getCollection( shortName + \".$\" + spec.name );\n"
"var mysize = coll.dataSize();\n"
"\n"
"total += coll.dataSize();\n"
"}\n"
");\n"
"return total;\n"
"}\n"
"\n"
"DBCollection.prototype.convertToCapped = function( bytes ){\n"
"if ( ! bytes )\n"
"throw \"have to specify # of bytes\";\n"
"return this._dbCommand( { convertToCapped : this._shortName , size : bytes } )\n"
"}\n"
"\n"
"DBCollection.prototype.exists = function(){\n"
"return this._db.system.namespaces.findOne( { name : this._fullName } );\n"
"}\n"
"\n"
"DBCollection.prototype.isCapped = function(){\n"
"var e = this.exists();\n"
"return ( e && e.options && e.options.capped ) ? true : false;\n"
"}\n"
"\n"
"DBCollection.prototype.group = function( params ){\n"
"params.ns = this._shortName;\n"
"return this._db.group( params );\n"
"}\n"
"\n"
"DBCollection.prototype.toString = function(){\n"
"return this.getFullName();\n"
"}\n"
"\n"
"DBCollection.prototype.shellPrint = DBCollection.prototype.toString;\n"
"\n"
"\n"
"\n"
"\n"
"if ( typeof DB == \"undefined\" ){\n"
"DB = function( mongo , name ){\n"
@ -671,7 +734,6 @@ const char * jsconcatcode =
"\n"
"while( c.hasNext() ) {\n"
"var obj = c.next();\n"
"\n"
"var key = {};\n"
"if( parms.key ) {\n"
"for( var i in parms.key )\n"
@ -680,17 +742,16 @@ const char * jsconcatcode =
"else {\n"
"key = parms.$keyf(obj);\n"
"}\n"
"\n"
"var aggObj = map[key];\n"
"var aggObj = map.get(key);\n"
"if( aggObj == null ) {\n"
"var newObj = Object.extend({}, key); \n"
"aggObj = map[key] = Object.extend(newObj, parms.initial)\n"
"aggObj = Object.extend(newObj, parms.initial)\n"
"map.put( key , aggObj );\n"
"}\n"
"parms.$reduce(obj, aggObj);\n"
"}\n"
"\n"
"var ret = map.values();\n"
"return ret;\n"
"return map.values();\n"
"}\n"
"\n"
"var parms = Object.extend({}, parmsObj);\n"
@ -750,13 +811,22 @@ const char * jsconcatcode =
"}\n"
"\n"
"DB.prototype.tojson = function(){\n"
"return this.toString();\n"
"return this._name;\n"
"}\n"
"\n"
"DB.prototype.toString = function(){\n"
"return this._name;\n"
"}\n"
"\n"
"DB.prototype.currentOp = function(){\n"
"return db.$cmd.sys.inprog.findOne();\n"
"}\n"
"DB.prototype.currentOP = DB.prototype.currentOp;\n"
"\n"
"DB.prototype.killOp = function(){\n"
"return db.$cmd.sys.killop.findOne();\n"
"}\n"
"DB.prototype.killOP = DB.prototype.killOp;\n"
"\n"
"/**\n"
"Get a replication log information summary.\n"
@ -1192,6 +1262,7 @@ const char * jsconcatcode =
"this._numReturned = 0;\n"
"this._special = false;\n"
"}\n"
"print( \"DBQuery probably won't have array access \" );\n"
"}\n"
"\n"
"\n"
@ -1290,6 +1361,18 @@ const char * jsconcatcode =
"throw \"count failed: \" + tojson( res );\n"
"}\n"
"\n"
"DBQuery.prototype.countReturn = function(){\n"
"var c = this.count();\n"
"\n"
"if ( this._skip )\n"
"c = c - this._skip;\n"
"\n"
"if ( this._limit > 0 && this._limit < c )\n"
"return this._limit;\n"
"\n"
"return c;\n"
"}\n"
"\n"
"/**\n"
"* iterative count - only for testing\n"
"*/\n"
@ -1454,11 +1537,26 @@ const char * jsconcatcode =
"} catch( e ) {\n"
"}\n"
"return false;\n"
"} );\n"
"}, \"unable to connect to mongo program on port \" + port, 10000 );\n"
"\n"
"return m;\n"
"}\n"
"\n"
"\n"
"\n"
"\n"
"startMongoProgramNoConnect = function() {\n"
"return _startMongoProgram.apply( null, arguments );\n"
"}\n"
"\n"
"myPort = function() {\n"
"var m = db.getMongo();\n"
"if ( m.host.match( /:/ ) )\n"
"return m.host.match( /:(.*)/ )[ 1 ];\n"
"else\n"
"return 27017;\n"
"}\n"
"\n"
"ShardingTest = function( testName , numServers , verboseLevel , numMongos ){\n"
"this._connections = [];\n"
"this._serverNames = [];\n"
@ -1539,11 +1637,12 @@ const char * jsconcatcode =
"throw \"command \" + tojson( cmd ) + \" failed: \" + tojson( res );\n"
"}\n"
"\n"
"MongodRunner = function( port, dbpath, peer, arbiter ) {\n"
"MongodRunner = function( port, dbpath, peer, arbiter, extraArgs ) {\n"
"this.port_ = port;\n"
"this.dbpath_ = dbpath;\n"
"this.peer_ = peer;\n"
"this.arbiter_ = arbiter;\n"
"this.extraArgs_ = extraArgs;\n"
"}\n"
"\n"
"MongodRunner.prototype.start = function( reuseData ) {\n"
@ -1564,6 +1663,11 @@ const char * jsconcatcode =
"args.push( \"1\" );\n"
"}\n"
"args.push( \"--nohttpinterface\" );\n"
"args.push( \"--bind_ip\" );\n"
"args.push( \"127.0.0.1\" );\n"
"if ( this.extraArgs_ ) {\n"
"args = args.concat( this.extraArgs_ );\n"
"}\n"
"if ( reuseData ) {\n"
"return startMongoProgram.apply( null, args );\n"
"} else {\n"
@ -1717,6 +1821,17 @@ const char * jsconcatcode =
"return ret;\n"
"}\n"
"\n"
"friendlyEqual = function( a , b ){\n"
"if ( a == b )\n"
"return true;\n"
"\n"
"if ( tojson( a ) == tojson( b ) )\n"
"return true;\n"
"\n"
"return false;\n"
"}\n"
"\n"
"\n"
"assert = function( b , msg ){\n"
"if ( b )\n"
"return;\n"
@ -1728,10 +1843,10 @@ const char * jsconcatcode =
"if ( a == b )\n"
"return;\n"
"\n"
"if ( a != null && b != null && a.toString() == b.toString() )\n"
"if ( ( a != null && b != null ) && friendlyEqual( a , b ) )\n"
"return;\n"
"\n"
"throw \"[\" + a + \"] != [\" + b + \"] are not equal : \" + msg;\n"
"throw \"[\" + tojson( a ) + \"] != [\" + tojson( b ) + \"] are not equal : \" + msg;\n"
"}\n"
"\n"
"assert.neq = function( a , b , msg ){\n"
@ -1741,15 +1856,17 @@ const char * jsconcatcode =
"throw \"[\" + a + \"] != [\" + b + \"] are equal : \" + msg;\n"
"}\n"
"\n"
"assert.soon = function( f, msg ) {\n"
"assert.soon = function( f, msg, timeout, interval ) {\n"
"var start = new Date();\n"
"timeout = timeout || 30000;\n"
"interval = interval || 200;\n"
"var last;\n"
"while( 1 ) {\n"
"if ( f() )\n"
"return;\n"
"if ( ( new Date() ).getTime() - start.getTime() > 30000 )\n"
"if ( ( new Date() ).getTime() - start.getTime() > timeout )\n"
"throw \"assert.soon failed: \" + f + \", msg:\" + msg;\n"
"sleep( 200 );\n"
"sleep( interval );\n"
"}\n"
"}\n"
"\n"
@ -1786,6 +1903,18 @@ const char * jsconcatcode =
"throw \"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"
"}\n"
"\n"
"assert.gt = function( a , b , msg ){\n"
"if ( a > b )\n"
"return;\n"
"throw a + \" is not greater than \" + b + \" : \" + msg;\n"
"}\n"
"\n"
"Object.extend = function( dst , src ){\n"
"for ( var k in src ){\n"
"dst[k] = src[k];\n"
@ -1886,19 +2015,23 @@ const char * jsconcatcode =
"\n"
"ObjectId.prototype.isObjectId = true;\n"
"\n"
"Thread = function(){\n"
"this.init.apply( this, arguments );\n"
"DBRef.prototype.fetch = function(){\n"
"assert( this.ns , \"need a ns\" );\n"
"assert( this.id , \"need an id\" );\n"
"\n"
"return db[ this.ns ].findOne( { _id : this.id } );\n"
"}\n"
"\n"
"if ( typeof( threadInject ) == \"function\" )\n"
"threadInject( Thread.prototype );\n"
"else\n"
"print( \"warning: thread management won't work\" );\n"
"DBRef.prototype.tojson = function(){\n"
"return \"{ 'ns' : \\\"\" + this.ns + \"\\\" , 'id' : \\\"\" + this.id + \"\\\" } \";\n"
"}\n"
"\n"
"fork = function() {\n"
"var t = new Thread( function() {} );\n"
"Thread.apply( t, arguments );\n"
"return t;\n"
"DBRef.prototype.toString = function(){\n"
"return \"DBRef \" + this.ns + \":\" + this.id;\n"
"}\n"
"\n"
"BinData.prototype.tojson = function(){\n"
"return \"BinData type: \" + this.type + \" len: \" + this.len;\n"
"}\n"
"\n"
"tojson = function( x ){\n"
@ -1917,8 +2050,12 @@ const char * jsconcatcode =
"case \"object\":\n"
"return tojsonObject( x );\n"
"\n"
"case \"function\":\n"
"return x.toString();\n"
"\n"
"\n"
"default:\n"
"throw \"can't handle type \" + ( typeof v );\n"
"throw \"tojson can't handle type \" + ( typeof x );\n"
"}\n"
"\n"
"}\n"
@ -1926,17 +2063,22 @@ const char * jsconcatcode =
"tojsonObject = function( x ){\n"
"assert.eq( ( typeof x ) , \"object\" , \"tojsonObject needs object, not [\" + ( typeof x ) + \"]\" );\n"
"\n"
"if ( x.tojson )\n"
"if ( typeof( x.tojson ) == \"function\" && x.tojson != tojson )\n"
"return x.tojson();\n"
"\n"
"var s = \"{\";\n"
"\n"
"var first = true;\n"
"for ( var k in x ){\n"
"\n"
"var val = x[k];\n"
"if ( val == DB.prototype || val == DBCollection.prototype )\n"
"continue;\n"
"\n"
"if ( first ) first = false;\n"
"else s += \" , \";\n"
"\n"
"s += \"\\\"\" + k + \"\\\" : \" + tojson( x[k] );\n"
"s += \"\\\"\" + k + \"\\\" : \" + tojson( val );\n"
"}\n"
"\n"
"return s + \"}\";\n"
@ -1965,6 +2107,14 @@ const char * jsconcatcode =
"\n"
"shellPrintHelper = function( x ){\n"
"\n"
"if ( typeof( x ) == \"undefined\" )\n"
"return;\n"
"\n"
"if ( x == null ){\n"
"print( \"null\" );\n"
"return;\n"
"}\n"
"\n"
"if ( typeof x != \"object\" )\n"
"return print( x );\n"
"\n"
@ -1979,6 +2129,24 @@ const char * jsconcatcode =
"print( tojson( x ) );\n"
"}\n"
"\n"
"execShellLine = function(){\n"
"var l = __line__.trim();\n"
"\n"
"var cmd = l.substring( 0 , ( l.indexOf( \" \" ) || l.length ) );\n"
"if ( cmd.length == 0 )\n"
"cmd = l;\n"
"\n"
"if ( shellHelper[ cmd ] ){\n"
"shellHelper( cmd , l.substring( cmd.length + 1 ).trim() );\n"
"return;\n"
"}\n"
"\n"
"var res = eval( l );\n"
"if ( typeof( res ) != \"undefined\" ){\n"
"shellPrintHelper( res );\n"
"}\n"
"}\n"
"\n"
"shellHelper = function( command , rest ){\n"
"command = command.trim();\n"
"var args = rest.trim().replace(/;$/,\"\").split( \"\\s+\" );\n"
@ -2024,8 +2192,10 @@ const char * jsconcatcode =
"return \"\";\n"
"}\n"
"\n"
"if ( what == \"users\" )\n"
"return db.system.users.find();\n"
"if ( what == \"users\" ){\n"
"db.system.users.find().forEach( printjson );\n"
"return \"\";\n"
"}\n"
"\n"
"if ( what == \"collections\" || what == \"tables\" ) {\n"
"db.getCollectionNames().forEach( function(x){print(x)} );\n"
@ -2041,21 +2211,44 @@ const char * jsconcatcode =
"\n"
"}\n"
"\n"
"\n"
"if ( typeof( Map ) == \"undefined\" ){\n"
"Map = function(){\n"
"print( \"warning: Map isn't a good thing to use\" );\n"
"this._data = [];\n"
"}\n"
"}\n"
"\n"
"Map.prototype.put = function( key , value ){\n"
"var o = this._get( key );\n"
"var old = o.value;\n"
"o.value = value;\n"
"return old;\n"
"}\n"
"\n"
"Map.prototype.get = function( key ){\n"
"return this._get( key ).value;\n"
"}\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"
"}\n"
"}\n"
"var o = { key : key , value : null };\n"
"this._data.push( o );\n"
"return o;\n"
"}\n"
"\n"
"Map.prototype.values = function(){\n"
"\n"
"var a = [];\n"
"for ( var k in this ){\n"
"var v = this[k];\n"
"if ( v == Map.prototype.values )\n"
"continue;\n"
"a.push( v );\n"
"return this._data.map( function(z){ return z.value } );\n"
"}\n"
"return a;\n"
"\n"
"Math.sigFig = function( x , N ){\n"
"if ( ! N ){\n"
"N = 3;\n"
"}\n"
"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"
;