From d507628f09d04c8091c57c7ad06aedbc30fb4b59 Mon Sep 17 00:00:00 2001 From: agirbal Date: Sun, 10 Jul 2011 17:37:12 -0700 Subject: [PATCH] SERVER-3176: autoIndexId not honored in mongo shell's createCollection command --- jstests/disk/norepeat.js | 2 +- jstests/index9.js | 8 ++++++++ shell/db.js | 5 ++++- shell/mongo_vstudio.cpp | 5 ++++- 4 files changed, 17 insertions(+), 3 deletions(-) diff --git a/jstests/disk/norepeat.js b/jstests/disk/norepeat.js index d9f1cd3b844..985fc3637ab 100644 --- a/jstests/disk/norepeat.js +++ b/jstests/disk/norepeat.js @@ -45,7 +45,7 @@ assert.throws( function() { c.next() }, [], "unexpected: object found" ); m.getDB( "local" ).getCollectionNames().forEach( function( x ) { assert( !x.match( /^temp/ ), "temp collection found" ); } ); t.drop(); -m.getDB( baseName ).createCollection( baseName, { capped:true, size:100000, autoIdIndex:false } ); +m.getDB( baseName ).createCollection( baseName, { capped:true, size:100000, autoIndexId:false } ); t = m.getDB( baseName ).getCollection( baseName ); t.insert( {_id:"a"} ); t.insert( {_id:"a"} ); diff --git a/jstests/index9.js b/jstests/index9.js index c83278310b3..04b900949ec 100644 --- a/jstests/index9.js +++ b/jstests/index9.js @@ -1,7 +1,15 @@ t = db.jstests_index9; +t.drop(); +db.createCollection( "jstests_index9" ); +assert.eq( 1, db.system.indexes.count( {ns: "test.jstests_index9"} ), "There should be 1 index with default collection" ); +t.drop(); +db.createCollection( "jstests_index9", {autoIndexId: true} ); +assert.eq( 1, db.system.indexes.count( {ns: "test.jstests_index9"} ), "There should be 1 index if autoIndexId: true" ); + t.drop(); db.createCollection( "jstests_index9", {autoIndexId:false} ); +assert.eq( 0, db.system.indexes.count( {ns: "test.jstests_index9"} ), "There should be 0 index if autoIndexId: false" ); t.createIndex( { _id:1 } ); assert.eq( 1, db.system.indexes.count( {ns: "test.jstests_index9"} ) ); t.createIndex( { _id:1 } ); diff --git a/shell/db.js b/shell/db.js index d5e946c7587..3b8dfc7b608 100644 --- a/shell/db.js +++ b/shell/db.js @@ -134,7 +134,10 @@ DB.prototype.auth = function( username , pass ){ */ DB.prototype.createCollection = function(name, opt) { var options = opt || {}; - var cmd = { create: name, capped: options.capped, size: options.size, max: options.max }; + var autoIndexId = true; + if (options.autoIndexId != undefined) + autoIndexId = options.autoIndexId; + var cmd = { create: name, capped: options.capped, size: options.size, max: options.max, autoIndexId: autoIndexId }; var res = this._dbCommand(cmd); return res; } diff --git a/shell/mongo_vstudio.cpp b/shell/mongo_vstudio.cpp index be0430503d2..c82171ab542 100644 --- a/shell/mongo_vstudio.cpp +++ b/shell/mongo_vstudio.cpp @@ -1831,7 +1831,10 @@ const StringData _jscode_raw_db = "*/\n" "DB.prototype.createCollection = function(name, opt) {\n" "var options = opt || {};\n" -"var cmd = { create: name, capped: options.capped, size: options.size, max: options.max };\n" +"var autoIndexId = true;\n" +"if (options.autoIndexId != undefined)\n" +"autoIndexId = options.autoIndexId;\n" +"var cmd = { create: name, capped: options.capped, size: options.size, max: options.max, autoIndexId: autoIndexId };\n" "var res = this._dbCommand(cmd);\n" "return res;\n" "}\n"