diff --git a/client/dbclient.cpp b/client/dbclient.cpp index ddeb56fa549..c079abad65e 100644 --- a/client/dbclient.cpp +++ b/client/dbclient.cpp @@ -391,6 +391,7 @@ namespace mongo { } bool DBClientWithCommands::createCollection(const string &ns, long long size, bool capped, int max, BSONObj *info) { + assert(!capped||size); BSONObj o; if ( info == 0 ) info = &o; BSONObjBuilder b; diff --git a/db/dbcommands.cpp b/db/dbcommands.cpp index d623145875c..8ff6582415d 100644 --- a/db/dbcommands.cpp +++ b/db/dbcommands.cpp @@ -826,11 +826,13 @@ namespace mongo { } virtual LockType locktype() const { return WRITE; } virtual void help( stringstream& help ) const { - help << "create a collection"; + help << "create a collection explicitly\n" + "{ create: [, capped: , size: , max: ] }"; } virtual bool run(const string& dbname , BSONObj& cmdObj, string& errmsg, BSONObjBuilder& result, bool fromRepl ) { string ns = dbname + '.' + cmdObj.firstElement().valuestr(); string err; + uassert(14832, "specify size: when capped is true", !cmdObj["capped"].trueValue() || cmdObj["size"].isNumber() || cmdObj.hasField("$nExtents")); bool ok = userCreateNS(ns.c_str(), cmdObj, err, ! fromRepl ); if ( !ok && !err.empty() ) errmsg = err; diff --git a/db/pdfile.cpp b/db/pdfile.cpp index e9cb0a5c371..6d11bc2d2af 100644 --- a/db/pdfile.cpp +++ b/db/pdfile.cpp @@ -227,7 +227,7 @@ namespace mongo { bool newCapped = false; int mx = 0; - if( options.getBoolField("capped") ) { + if( options["capped"].trueValue() ) { newCapped = true; BSONElement e = options.getField("max"); if ( e.isNumber() ) { diff --git a/dbtests/clienttests.cpp b/dbtests/clienttests.cpp index f51b76578a1..a64894b43c1 100644 --- a/dbtests/clienttests.cpp +++ b/dbtests/clienttests.cpp @@ -156,7 +156,7 @@ namespace ClientTests { public: Create() : Base( "Create" ) {} void run() { - db.createCollection( "unittests.clienttests.create", 0, true ); + db.createCollection( "unittests.clienttests.create", 4096, true ); BSONObj info; ASSERT( db.runCommand( "unittests", BSON( "collstats" << "clienttests.create" ), info ) ); } diff --git a/dbtests/querytests.cpp b/dbtests/querytests.cpp index e208c995173..a60a7a7898f 100644 --- a/dbtests/querytests.cpp +++ b/dbtests/querytests.cpp @@ -238,7 +238,7 @@ namespace QueryTests { } void run() { const char *ns = "unittests.querytests.ReturnOneOfManyAndTail"; - client().createCollection( ns, 0, true ); + client().createCollection( ns, 1024, true ); insert( ns, BSON( "a" << 0 ) ); insert( ns, BSON( "a" << 1 ) ); insert( ns, BSON( "a" << 2 ) ); @@ -257,7 +257,7 @@ namespace QueryTests { } void run() { const char *ns = "unittests.querytests.TailNotAtEnd"; - client().createCollection( ns, 0, true ); + client().createCollection( ns, 2047, true ); insert( ns, BSON( "a" << 0 ) ); insert( ns, BSON( "a" << 1 ) ); insert( ns, BSON( "a" << 2 ) ); @@ -282,7 +282,7 @@ namespace QueryTests { } void run() { const char *ns = "unittests.querytests.EmptyTail"; - client().createCollection( ns, 0, true ); + client().createCollection( ns, 1900, true ); auto_ptr< DBClientCursor > c = client().query( ns, Query().hint( BSON( "$natural" << 1 ) ), 2, 0, 0, QueryOption_CursorTailable ); ASSERT_EQUALS( 0, c->getCursorId() ); ASSERT( c->isDead() ); @@ -300,7 +300,7 @@ namespace QueryTests { } void run() { const char *ns = "unittests.querytests.TailableDelete"; - client().createCollection( ns, 0, true, 2 ); + client().createCollection( ns, 1300, true, 2 ); insert( ns, BSON( "a" << 0 ) ); insert( ns, BSON( "a" << 1 ) ); auto_ptr< DBClientCursor > c = client().query( ns, Query().hint( BSON( "$natural" << 1 ) ), 2, 0, 0, QueryOption_CursorTailable ); @@ -321,7 +321,7 @@ namespace QueryTests { } void run() { const char *ns = "unittests.querytests.TailableInsertDelete"; - client().createCollection( ns, 0, true ); + client().createCollection( ns, 1330, true ); insert( ns, BSON( "a" << 0 ) ); insert( ns, BSON( "a" << 1 ) ); auto_ptr< DBClientCursor > c = client().query( ns, Query().hint( BSON( "$natural" << 1 ) ), 2, 0, 0, QueryOption_CursorTailable ); @@ -366,7 +366,7 @@ namespace QueryTests { void run() { const char *ns = "unittests.querytests.TailableQueryOnId"; BSONObj info; - client().runCommand( "unittests", BSON( "create" << "querytests.TailableQueryOnId" << "capped" << true << "autoIndexId" << true ), info ); + client().runCommand( "unittests", BSON( "create" << "querytests.TailableQueryOnId" << "capped" << true << "size" << 1300 << "autoIndexId" << true ), info ); insertA( ns, 0 ); insertA( ns, 1 ); auto_ptr< DBClientCursor > c1 = client().query( ns, QUERY( "a" << GT << -1 ), 0, 0, 0, QueryOption_CursorTailable ); diff --git a/shell/mongo_vstudio.cpp b/shell/mongo_vstudio.cpp index f39b9302f6a..24e26305198 100644 --- a/shell/mongo_vstudio.cpp +++ b/shell/mongo_vstudio.cpp @@ -1744,8 +1744,8 @@ const StringData _jscode_raw_db = "this.getCollection( \"system.users\" ).remove( { user : username } );\n" "}\n" "\n" -"DB.prototype.__pwHash = function( nonce64, username, pass ) {\n" -"return hex_md5( nonce64 + username + hex_md5( username + \":mongo:\" + pass ) );\n" +"DB.prototype.__pwHash = function( nonce, username, pass ) {\n" +"return hex_md5( nonce + username + hex_md5( username + \":mongo:\" + pass ) );\n" "}\n" "\n" "DB.prototype.auth = function( username , pass ){\n" @@ -1755,8 +1755,8 @@ const StringData _jscode_raw_db = "{\n" "authenticate : 1 ,\n" "user : username ,\n" -"nonce64 : n.nonce64 ,\n" -"key : this.__pwHash( n.nonce64, username, pass )\n" +"nonce : n.nonce ,\n" +"key : this.__pwHash( n.nonce, username, pass )\n" "}\n" ");\n" "\n" @@ -1832,14 +1832,27 @@ const StringData _jscode_raw_db = "return this._dbCommand( { dropDatabase: 1 } );\n" "}\n" "\n" -"\n" -"DB.prototype.shutdownServer = function() {\n" +"/**\n" +"* Shuts down the database. Must be run while using the admin database.\n" +"* @param opts Options for shutdown. Possible options are:\n" +"* - force: (boolean) if the server should shut down, even if there is no\n" +"* up-to-date slave\n" +"* - timeoutSecs: (number) the server will continue checking over timeoutSecs\n" +"* if any other servers have caught up enough for it to shut down.\n" +"*/\n" +"DB.prototype.shutdownServer = function(opts) {\n" "if( \"admin\" != this._name ){\n" "return \"shutdown command only works with the admin database; try 'use admin'\";\n" "}\n" "\n" +"cmd = {\"shutdown\" : 1};\n" +"opts = opts || {};\n" +"for (var o in opts) {\n" +"cmd[o] = opts[o];\n" +"}\n" +"\n" "try {\n" -"var res = this._dbCommand(\"shutdown\");\n" +"var res = this.runCommand(cmd);\n" "if( res )\n" "throw \"shutdownServer failed: \" + res.errmsg;\n" "throw \"shutdownServer failed\";\n" @@ -1925,7 +1938,7 @@ const StringData _jscode_raw_db = "fromhost = fromhost || \"\";\n" "if ( username && password ) {\n" "var n = this._adminCommand( { copydbgetnonce : 1, fromhost:fromhost } );\n" -"return this._adminCommand( { copydb:1, fromhost:fromhost, fromdb:fromdb, todb:todb, username:username, nonce64:n.nonce64, key:this.__pwHash( n.nonce64, username, password ) } );\n" +"return this._adminCommand( { copydb:1, fromhost:fromhost, fromdb:fromdb, todb:todb, username:username, nonce:n.nonce, key:this.__pwHash( n.nonce, username, password ) } );\n" "} else {\n" "return this._adminCommand( { copydb:1, fromhost:fromhost, fromdb:fromdb, todb:todb } );\n" "}\n"