diff options
author | Randolph Tan <randolph@10gen.com> | 2014-03-12 11:50:31 -0400 |
---|---|---|
committer | Randolph Tan <randolph@10gen.com> | 2014-03-13 15:58:06 -0400 |
commit | a08c9f4ee6d5389b3a6a96f093d8a1fdecc9cb8d (patch) | |
tree | ddc6f6395a28f0ccdde6bd2bfff3b81171c6069f /jstests/core | |
parent | dc28d4a2d9336904ce302c9c3c8099cb27f402eb (diff) | |
download | mongo-a08c9f4ee6d5389b3a6a96f093d8a1fdecc9cb8d.tar.gz |
SERVER-13028 fix shell to use createIndex command for createIndex method
Diffstat (limited to 'jstests/core')
26 files changed, 96 insertions, 95 deletions
diff --git a/jstests/core/bad_index_plugin.js b/jstests/core/bad_index_plugin.js index 98ebdb9bb28..c22bba5e0cc 100644 --- a/jstests/core/bad_index_plugin.js +++ b/jstests/core/bad_index_plugin.js @@ -1,11 +1,11 @@ // SERVER-5826 ensure you can't build an index with a non-existent plugin t = db.bad_index_plugin; -assert.writeOK(t.ensureIndex({good: 1})); +assert.commandWorked(t.ensureIndex({ good: 1 })); assert.eq(t.getIndexes().length, 2); // good + _id var err = t.ensureIndex({bad: 'bad'}); -assert.writeError(err); -assert(err.getWriteError().code >= 0); +assert.commandFailed(err); +assert(err.code >= 0); assert.eq(t.getIndexes().length, 2); // good + _id (no bad) diff --git a/jstests/core/fts_index.js b/jstests/core/fts_index.js index 2c61cd811b0..af927c86f48 100644 --- a/jstests/core/fts_index.js +++ b/jstests/core/fts_index.js @@ -14,22 +14,22 @@ coll.getDB().createCollection(coll.getName()); // // Spec passes text-specific index validation. -assert.writeOK(coll.ensureIndex({a: "text"}, {name: indexName, default_language: "spanish"})); +assert.commandWorked(coll.ensureIndex({a: "text"}, {name: indexName, default_language: "spanish"})); assert.eq(1, coll.getDB().system.indexes.count({ns: coll.getFullName(), name: indexName})); coll.dropIndexes(); // Spec fails text-specific index validation ("spanglish" unrecognized). -assert.writeError(coll.ensureIndex({a: "text"}, {name: indexName, default_language: "spanglish"})); +assert.commandFailed(coll.ensureIndex({a: "text"}, {name: indexName, default_language: "spanglish"})); assert.eq(0, coll.system.indexes.count({ns: coll.getFullName(), name: indexName})); coll.dropIndexes(); // Spec passes general index validation. -assert.writeOK(coll.ensureIndex({"$**": "text"}, {name: indexName})); +assert.commandWorked(coll.ensureIndex({"$**": "text"}, {name: indexName})); assert.eq(1, coll.getDB().system.indexes.count({ns: coll.getFullName(), name: indexName})); coll.dropIndexes(); // Spec fails general index validation ("a.$**" invalid field name for key). -assert.writeError(coll.ensureIndex({"a.$**": "text"}, {name: indexName})); +assert.commandFailed(coll.ensureIndex({"a.$**": "text"}, {name: indexName})); assert.eq(0, coll.getDB().system.indexes.count({ns: coll.getFullName(), name: indexName})); coll.dropIndexes(); @@ -40,56 +40,56 @@ coll.dropIndexes(); // Can create a text index on a collection where no documents have invalid language_override. coll.insert({a: ""}); coll.insert({a: "", language: "spanish"}); -assert.writeOK(coll.ensureIndex({a: "text"})); +assert.commandWorked(coll.ensureIndex({a: "text"})); coll.drop(); // Can't create a text index on a collection containing document with an invalid language_override. coll.insert({a: "", language: "spanglish"}); -assert.writeError(coll.ensureIndex({a: "text"})); +assert.commandFailed(coll.ensureIndex({a: "text"})); coll.drop(); // Can insert documents with valid language_override into text-indexed collection. -assert.writeOK(coll.ensureIndex({a: "text"})); +assert.commandWorked(coll.ensureIndex({a: "text"})); coll.insert({a: ""}); assert.writeOK( coll.insert({a: "", language: "spanish"})); coll.drop(); // Can't insert documents with invalid language_override into text-indexed collection. -assert.writeOK(coll.ensureIndex({a: "text"})); +assert.commandWorked(coll.ensureIndex({a: "text"})); assert.writeError( coll.insert({a: "", language: "spanglish"})); coll.drop(); // // 3. Collections may have at most one text index. // -assert.writeOK(coll.ensureIndex({a: 1, b: "text", c: 1})); +assert.commandWorked(coll.ensureIndex({a: 1, b: "text", c: 1})); assert.eq(2, coll.getIndexes().length); // ensureIndex() becomes a no-op on an equivalent index spec. -assert.writeOK(coll.ensureIndex({a: 1, b: "text", c: 1})); +assert.commandWorked(coll.ensureIndex({a: 1, b: "text", c: 1})); assert.eq(2, coll.getIndexes().length); -assert.writeOK(coll.ensureIndex({a: 1, b: "text", c: 1}, {background: true})); +assert.commandWorked(coll.ensureIndex({a: 1, b: "text", c: 1}, {background: true})); assert.eq(2, coll.getIndexes().length); -assert.writeOK(coll.ensureIndex({a: 1, _fts: "text", _ftsx: 1, c: 1}, {weights: {b: 1}})); +assert.commandWorked(coll.ensureIndex({a: 1, _fts: "text", _ftsx: 1, c: 1}, {weights: {b: 1}})); assert.eq(2, coll.getIndexes().length); -assert.writeOK(coll.ensureIndex({a: 1, b: "text", c: 1}, {default_language: "english"})); +assert.commandWorked(coll.ensureIndex({a: 1, b: "text", c: 1}, {default_language: "english"})); assert.eq(2, coll.getIndexes().length); -assert.writeOK(coll.ensureIndex({a: 1, b: "text", c: 1}, {textIndexVersion: 2})); +assert.commandWorked(coll.ensureIndex({a: 1, b: "text", c: 1}, {textIndexVersion: 2})); assert.eq(2, coll.getIndexes().length); -assert.writeOK(coll.ensureIndex({a: 1, b: "text", c: 1}, {language_override: "language"})); +assert.commandWorked(coll.ensureIndex({a: 1, b: "text", c: 1}, {language_override: "language"})); assert.eq(2, coll.getIndexes().length); // ensureIndex() fails if a second text index would be built. -assert.writeError(coll.ensureIndex({a: 1, _fts: "text", _ftsx: 1, c: 1}, {weights: {d: 1}})); -assert.writeError(coll.ensureIndex({a: 1, b: "text", c: 1}, {default_language: "none"})); -assert.writeError(coll.ensureIndex({a: 1, b: "text", c: 1}, {textIndexVersion: 1})); -assert.writeError(coll.ensureIndex({a: 1, b: "text", c: 1}, {language_override: "idioma"})); -assert.writeError(coll.ensureIndex({a: 1, b: "text", c: 1}, {weights: {d: 1}})); -assert.writeError(coll.ensureIndex({a: 1, b: "text", d: 1})); -assert.writeError(coll.ensureIndex({a: 1, d: "text", c: 1})); -assert.writeError(coll.ensureIndex({b: "text"})); -assert.writeError(coll.ensureIndex({b: "text", c: 1})); -assert.writeError(coll.ensureIndex({a: 1, b: "text"})); +assert.commandFailed(coll.ensureIndex({a: 1, _fts: "text", _ftsx: 1, c: 1}, {weights: {d: 1}})); +assert.commandFailed(coll.ensureIndex({a: 1, b: "text", c: 1}, {default_language: "none"})); +assert.commandFailed(coll.ensureIndex({a: 1, b: "text", c: 1}, {textIndexVersion: 1})); +assert.commandFailed(coll.ensureIndex({a: 1, b: "text", c: 1}, {language_override: "idioma"})); +assert.commandFailed(coll.ensureIndex({a: 1, b: "text", c: 1}, {weights: {d: 1}})); +assert.commandFailed(coll.ensureIndex({a: 1, b: "text", d: 1})); +assert.commandFailed(coll.ensureIndex({a: 1, d: "text", c: 1})); +assert.commandFailed(coll.ensureIndex({b: "text"})); +assert.commandFailed(coll.ensureIndex({b: "text", c: 1})); +assert.commandFailed(coll.ensureIndex({a: 1, b: "text"})); coll.dropIndexes(); @@ -97,7 +97,7 @@ coll.dropIndexes(); // 4. Text indexes properly handle large keys. // -assert.writeOK(coll.ensureIndex({a: "text"})); +assert.commandWorked(coll.ensureIndex({a: "text"})); var longstring = ""; var longstring2 = ""; diff --git a/jstests/core/geo10.js b/jstests/core/geo10.js index b122da99f2a..e098d4eef11 100644 --- a/jstests/core/geo10.js +++ b/jstests/core/geo10.js @@ -3,7 +3,7 @@ coll = db.geo10 coll.drop(); -assert.writeOK( db.geo10.ensureIndex( { c : '2d', t : 1 }, { min : 0, max : Math.pow( 2, 40 ) } )); +assert.commandWorked( db.geo10.ensureIndex( { c : '2d', t : 1 }, { min : 0, max : Math.pow( 2, 40 ) } )); assert( db.system.indexes.count({ ns : "test.geo10" }) == 2, "A3" ) printjson( db.system.indexes.find().toArray() ) diff --git a/jstests/core/geo4.js b/jstests/core/geo4.js index c1be468bb52..e5ca6584e3e 100644 --- a/jstests/core/geo4.js +++ b/jstests/core/geo4.js @@ -4,8 +4,8 @@ t.drop(); t.insert( { zip : "06525" , loc : [ 41.352964 , 73.01212 ] } ); var err = t.ensureIndex( { loc : "2d" }, { bits : 33 } ); -assert.writeError(err); -assert( err.getWriteError().errmsg.indexOf("bits in geo index must be between 1 and 32") >= 0, +assert.commandFailed(err); +assert( err.errmsg.indexOf("bits in geo index must be between 1 and 32") >= 0, tojson( err )); -assert.writeOK(t.ensureIndex( { loc : "2d" }, { bits : 32 } )); +assert.commandWorked(t.ensureIndex( { loc : "2d" }, { bits : 32 } )); diff --git a/jstests/core/geo_allowedcomparisons.js b/jstests/core/geo_allowedcomparisons.js index 61eb3f43e52..121492a26d4 100644 --- a/jstests/core/geo_allowedcomparisons.js +++ b/jstests/core/geo_allowedcomparisons.js @@ -83,7 +83,7 @@ t.dropIndex({geo: "2d"}) runTests(); // 2dsphere index now. -assert.writeOK( t.ensureIndex({geo: "2dsphere"}) ); +assert.commandWorked( t.ensureIndex({geo: "2dsphere"}) ); // 2dsphere does not support arrays of points. assert.writeError(t.insert({geo: [geojsonPoint2, geojsonPoint]})); runTests(); diff --git a/jstests/core/geo_array0.js b/jstests/core/geo_array0.js index 39c7b10c083..e93821e41ca 100644 --- a/jstests/core/geo_array0.js +++ b/jstests/core/geo_array0.js @@ -9,7 +9,7 @@ function test(index) { assert.writeOK( res ); if (index) { - assert.writeOK(t.ensureIndex( { loc : "2d", zip : 1 } )); + assert.commandWorked(t.ensureIndex( { loc : "2d", zip : 1 } )); assert.eq( 2, t.getIndexKeys().length ) } diff --git a/jstests/core/geo_array2.js b/jstests/core/geo_array2.js index acfc6a15abf..c6cbe01ef8e 100644 --- a/jstests/core/geo_array2.js +++ b/jstests/core/geo_array2.js @@ -26,7 +26,7 @@ for( var i = -1; i < 2; i++ ){ } } -assert.writeOK(t.ensureIndex({ loc : "2d" , type : 1 })); +assert.commandWorked(t.ensureIndex({ loc : "2d" , type : 1 })); print( "Starting testing phase... ") diff --git a/jstests/core/geo_invalid_polygon.js b/jstests/core/geo_invalid_polygon.js index 9ccf619dae5..1e31e0b2fe5 100644 --- a/jstests/core/geo_invalid_polygon.js +++ b/jstests/core/geo_invalid_polygon.js @@ -19,11 +19,12 @@ var geometry = { }; t.insert({_id: 42, geometry: geometry}); -var err = assert.writeError(t.createIndex({geometry: '2dsphere'})); +var err = t.createIndex({geometry: '2dsphere'}); +assert.commandFailed(err); // Document's _id should be in error message. assert( - -1 != err.getWriteError().errmsg.indexOf('42'), + -1 != err.errmsg.indexOf('42'), "Error message didn't contain document _id.\nMessage: \"" + err.errmsg + '"\n' ); diff --git a/jstests/core/geo_multikey1.js b/jstests/core/geo_multikey1.js index ce55609db25..7bf5cfaafe1 100644 --- a/jstests/core/geo_multikey1.js +++ b/jstests/core/geo_multikey1.js @@ -12,8 +12,8 @@ for( i = 0; i < 10; ++i ) { t.save( {loc:locArr,a:arr,b:arr,c:arr} ); // Parallel arrays are allowed for geo indexes. -assert.writeOK(t.ensureIndex( {loc:'2d',a:1,b:1,c:1} )); +assert.commandWorked(t.ensureIndex( {loc:'2d',a:1,b:1,c:1} )); // Parallel arrays are not allowed for normal indexes. -assert.writeError(t.ensureIndex( {loc:1,a:1,b:1,c:1} )); +assert.commandFailed(t.ensureIndex( {loc:1,a:1,b:1,c:1} )); diff --git a/jstests/core/geo_multinest0.js b/jstests/core/geo_multinest0.js index c15eb7d60d7..634d581589c 100644 --- a/jstests/core/geo_multinest0.js +++ b/jstests/core/geo_multinest0.js @@ -11,7 +11,7 @@ var res = t.insert( { zip : "10003", data : [ { loc : [ 30, 30 ], type : "home" { loc : [ 50, 50 ], type : "work" } ] } ); assert.writeOK( res ); -assert.writeOK(t.ensureIndex( { "data.loc" : "2d", zip : 1 } )); +assert.commandWorked(t.ensureIndex( { "data.loc" : "2d", zip : 1 } )); assert.eq( 2, t.getIndexKeys().length ) res = t.insert( { zip : "10004", data : [ { loc : [ 40, 40 ], type : "home" }, @@ -41,7 +41,7 @@ t.insert( { zip : "10002", data : [ { loc : [ 20, 20 ], type : "home" }, res = t.insert({ zip: "10003", data: [{ loc: [{ x: 30, y: 30 }, [ 50, 50 ]], type: "home" }]}); assert( !res.hasWriteErrors() ); -assert.writeOK(t.ensureIndex( { "data.loc" : "2d", zip : 1 } )); +assert.commandWorked(t.ensureIndex( { "data.loc" : "2d", zip : 1 } )); assert.eq( 2, t.getIndexKeys().length ) res = t.insert( { zip : "10004", data : [ { loc : [ 40, 40 ], type : "home" }, diff --git a/jstests/core/geo_multinest1.js b/jstests/core/geo_multinest1.js index 478e2ab83e4..9d63e72eb79 100644 --- a/jstests/core/geo_multinest1.js +++ b/jstests/core/geo_multinest1.js @@ -11,7 +11,7 @@ var res = t.insert( { zip : "10003", data : [ { loc : [ 30, 30 ], type : "home" { loc : [ 49, 49 ], type : "work" } ] } ); assert.writeOK( res ); -assert.writeOK(t.ensureIndex( { "data.loc" : "2d", zip : 1 } )); +assert.commandWorked(t.ensureIndex( { "data.loc" : "2d", zip : 1 } )); assert.eq( 2, t.getIndexKeys().length ) res = t.insert( { zip : "10004", data : [ { loc : [ 40, 40 ], type : "home" }, diff --git a/jstests/core/geo_polygon1.js b/jstests/core/geo_polygon1.js index 11f17910306..7af6d06bebd 100644 --- a/jstests/core/geo_polygon1.js +++ b/jstests/core/geo_polygon1.js @@ -40,7 +40,7 @@ pacman = [ ]; t.save({loc: [1,3] }); // Add a point that's in -assert.writeOK(t.ensureIndex( { loc : "2d" } )); +assert.commandWorked(t.ensureIndex( { loc : "2d" } )); assert.eq( 1 , t.find({loc : { $within : { $polygon : pacman }}} ).count() , "Pacman single point" ); diff --git a/jstests/core/geo_s2index.js b/jstests/core/geo_s2index.js index 974e4578dce..fea45dbb901 100755 --- a/jstests/core/geo_s2index.js +++ b/jstests/core/geo_s2index.js @@ -101,14 +101,14 @@ assert.writeOK(res); t.drop(); t.save({loc: [0,0]}) res = t.ensureIndex({ loc: "2dsphere" }, { finestIndexedLevel: 31, coarsestIndexedLevel: 5 }); -assert.writeError(res); +assert.commandFailed(res); t.drop(); t.save({loc: [0,0]}) res = t.ensureIndex({ loc: "2dsphere" }, { finestIndexedLevel: 30, coarsestIndexedLevel: 0 }); -assert.writeOK(res); +assert.commandWorked(res); t.drop(); t.save({loc: [0,0]}) res = t.ensureIndex({ loc: "2dsphere" }, { finestIndexedLevel: 30, coarsestIndexedLevel: -1 }); -assert.writeError(res); +assert.commandFailed(res); diff --git a/jstests/core/geo_s2nongeoarray.js b/jstests/core/geo_s2nongeoarray.js index 02f307fbab1..85a01aaedae 100644 --- a/jstests/core/geo_s2nongeoarray.js +++ b/jstests/core/geo_s2nongeoarray.js @@ -8,7 +8,7 @@ var data = {geo: oldPoint, nonGeo: [123,456], otherNonGeo: [{b:[1,2]},{b:[3,4]}] t.drop(); assert.writeOK(t.insert(data)); -assert.writeOK(t.ensureIndex({otherNonGeo: 1})); +assert.commandWorked(t.ensureIndex({ otherNonGeo: 1 })); assert.eq(1, t.find({otherNonGeo: {b:[1,2]}}).itcount()); assert.eq(0, t.find({otherNonGeo: 1}).itcount()); assert.eq(1, t.find({'otherNonGeo.b': 1}).itcount()); diff --git a/jstests/core/geo_s2validindex.js b/jstests/core/geo_s2validindex.js index bc8a569e559..c6dd8be58d9 100644 --- a/jstests/core/geo_s2validindex.js +++ b/jstests/core/geo_s2validindex.js @@ -6,19 +6,19 @@ var coll = db.getCollection("twodspherevalid"); // Valid index coll.drop(); -assert.writeOK(coll.ensureIndex({geo : "2dsphere", other : 1})); +assert.commandWorked(coll.ensureIndex({geo : "2dsphere", other : 1})); // Valid index coll.drop(); -assert.writeOK(coll.ensureIndex({geo : "2dsphere", other : 1, geo2 : "2dsphere"})); +assert.commandWorked(coll.ensureIndex({geo : "2dsphere", other : 1, geo2 : "2dsphere"})); // Invalid index, using hash with 2dsphere coll.drop(); -assert.writeError(coll.ensureIndex({geo : "2dsphere", other : "hash"})); +assert.commandFailed(coll.ensureIndex({geo : "2dsphere", other : "hash"})); // Invalid index, using 2d with 2dsphere coll.drop(); -assert.writeError(coll.ensureIndex({geo : "2dsphere", other : "2d"})); +assert.commandFailed(coll.ensureIndex({geo : "2dsphere", other : "2d"})); jsTest.log("Success!"); diff --git a/jstests/core/index10.js b/jstests/core/index10.js index d86402e41af..41f58816f1f 100644 --- a/jstests/core/index10.js +++ b/jstests/core/index10.js @@ -13,8 +13,8 @@ t.ensureIndex( {i:1} ); assert.eq( 5, t.count() ); t.dropIndexes(); var err = t.ensureIndex( {i:1}, true ); -assert.writeError(err) -assert.eq( 11000, err.getWriteError().code ); +assert.commandFailed(err) +assert.eq( 11000, err.code ); assert( 1 == db.system.indexes.count( {ns:"test.jstests_index10" } ), "only id index" ); // t.dropIndexes(); diff --git a/jstests/core/index_many.js b/jstests/core/index_many.js index f14f3c3e0fc..70f39c4719c 100644 --- a/jstests/core/index_many.js +++ b/jstests/core/index_many.js @@ -23,7 +23,7 @@ function f() { x++; } - assert.writeError(lastErr, "should have got an error 'too many indexes'"); + assert.commandFailed(lastErr, "should have got an error 'too many indexes'"); // 40 is the limit currently lim = t.getIndexes().length; diff --git a/jstests/core/index_sparse1.js b/jstests/core/index_sparse1.js index fbcc20a9217..1a525f53d8a 100644 --- a/jstests/core/index_sparse1.js +++ b/jstests/core/index_sparse1.js @@ -28,7 +28,7 @@ assert.eq( 1 , t.getIndexes().length , "C3" ) t.remove( { _id : 2 } ) // test that we can't create a unique index without sparse -assert.writeError( t.ensureIndex( { x : 1 } , { unique : 1 } )); +assert.commandFailed( t.ensureIndex( { x : 1 } , { unique : 1 } )); assert.eq( 1 , t.getIndexes().length , "D2" ) diff --git a/jstests/core/indexes_on_indexes.js b/jstests/core/indexes_on_indexes.js index 807c1e25bfd..59ee9bb68c5 100644 --- a/jstests/core/indexes_on_indexes.js +++ b/jstests/core/indexes_on_indexes.js @@ -3,7 +3,7 @@ t = db.getSiblingDB("indexes_on_indexes"); printjson(t.system.indexes.getIndexes()); assert.eq(t.system.indexes.getIndexes().length, 0); print("trying via ensureIndex"); -assert.throws(t.system.indexes.ensureIndex({_id:1})); +assert.commandFailed(t.system.indexes.ensureIndex({_id:1})); printjson(t.system.indexes.getIndexes()); assert.eq(t.system.indexes.getIndexes().length, 0); print("trying via createIndex"); diff --git a/jstests/core/indexi.js b/jstests/core/indexi.js index bfd9d13e15c..d0e77471fda 100644 --- a/jstests/core/indexi.js +++ b/jstests/core/indexi.js @@ -21,7 +21,7 @@ function checkFailingOperations() { expectWriteError(function() { return idx.update({ x: 1 }, { x: 2 }); }); expectWriteError(function() { return idx.remove({ x: 1 }); }); assert.commandFailed( idx.runCommand( 'compact' ) ); - assert.writeError(idx.ensureIndex({ x: 1 })); + assert.commandFailed( idx.ensureIndex({ x: 1 })); } // Check with base collection not present. diff --git a/jstests/core/indexo.js b/jstests/core/indexo.js index c9c9424b4ef..4875003faaa 100644 --- a/jstests/core/indexo.js +++ b/jstests/core/indexo.js @@ -5,11 +5,11 @@ var coll = db.jstests_indexo; coll.drop(); // Can create a dropDups index on non-capped collection. -assert.writeOK(coll.ensureIndex({x: 1}, {dropDups: true})); +assert.commandWorked(coll.ensureIndex({ x: 1 }, { dropDups: true })); coll.drop(); // Cannot create a dropDups index on non-capped collection. db.createCollection("jstests_indexy", {capped: true, size: 1024}); coll = db.jstests_indexy; -assert.writeError(coll.ensureIndex({x: 1}, {dropDups: true})); +assert.commandFailed(coll.ensureIndex({x: 1}, {dropDups: true})); coll.drop(); diff --git a/jstests/core/indexp.js b/jstests/core/indexp.js index cd72eeeebf5..c2a6866fc12 100644 --- a/jstests/core/indexp.js +++ b/jstests/core/indexp.js @@ -6,18 +6,18 @@ var coll = db.jstests_indexp; // Empty field checks. -assert.writeError(coll.ensureIndex({ 'a..b': 1 })); -assert.writeError(coll.ensureIndex({ '.a': 1 })); -assert.writeError(coll.ensureIndex({ 'a.': 1 })); -assert.writeError(coll.ensureIndex({ '.': 1 })); -assert.writeError(coll.ensureIndex({ '': 1 })); -assert.writeOK(coll.ensureIndex({ 'a.b': 1 })); +assert.commandFailed(coll.ensureIndex({ 'a..b': 1 })); +assert.commandFailed(coll.ensureIndex({ '.a': 1 })); +assert.commandFailed(coll.ensureIndex({ 'a.': 1 })); +assert.commandFailed(coll.ensureIndex({ '.': 1 })); +assert.commandFailed(coll.ensureIndex({ '': 1 })); +assert.commandWorked(coll.ensureIndex({ 'a.b': 1 })); // '$'-prefixed field checks. -assert.writeError(coll.ensureIndex({ '$a': 1 })); -assert.writeError(coll.ensureIndex({ 'a.$b': 1 })); -assert.writeError(coll.ensureIndex({ '$db': 1 })); -assert.writeOK(coll.ensureIndex({ 'a$ap': 1 })); // $ in middle is ok -assert.writeOK(coll.ensureIndex({ 'a.$id': 1 })); // $id/$db/$ref are execptions +assert.commandFailed(coll.ensureIndex({ '$a': 1 })); +assert.commandFailed(coll.ensureIndex({ 'a.$b': 1 })); +assert.commandFailed(coll.ensureIndex({ '$db': 1 })); +assert.commandWorked(coll.ensureIndex({ 'a$ap': 1 })); // $ in middle is ok +assert.commandWorked(coll.ensureIndex({ 'a.$id': 1 })); // $id/$db/$ref are execptions coll.dropIndexes(); diff --git a/jstests/core/indexu.js b/jstests/core/indexu.js index 9031d827bf4..d1ef13d0468 100644 --- a/jstests/core/indexu.js +++ b/jstests/core/indexu.js @@ -10,19 +10,19 @@ var noDupDoc = {a:[{'1':1}]}; // Test that we can't index dupDoc. assert.writeOK( t.save( dupDoc )); -assert.writeError(t.ensureIndex( {'a.0':1} )); +assert.commandFailed(t.ensureIndex( {'a.0':1} )); t.remove({}); -assert.writeOK(t.ensureIndex( {'a.0':1} )); +assert.commandWorked(t.ensureIndex( {'a.0':1} )); assert.writeError( t.save( dupDoc )); // Test that we can't index dupDoc2. t.drop(); assert.writeOK(t.save( dupDoc2 )); -assert.writeError(t.ensureIndex( {'a.1':1} )); +assert.commandFailed(t.ensureIndex( {'a.1':1} )); t.remove({}); -assert.writeOK(t.ensureIndex( {'a.1':1} )); +assert.commandWorked(t.ensureIndex( {'a.1':1} )); assert.writeError(t.save( dupDoc2 )); // Test that we can index dupDoc with a different index. @@ -49,8 +49,8 @@ assert.writeError( t.save( {a:[{'1':1},4]} )); // Test that we can index noDupDoc. t.drop(); t.save( noDupDoc ); -assert.writeOK(t.ensureIndex( {'a.0':1} )); -assert.writeOK(t.ensureIndex( {'a.1':1} )); +assert.commandWorked(t.ensureIndex( {'a.0':1} )); +assert.commandWorked(t.ensureIndex( {'a.1':1} )); t.drop(); t.ensureIndex( {'a.0':1} ); @@ -66,40 +66,40 @@ assert.eq( 1, t.find( {'a.0':{'1':1}} ).hint( {$natural:1} ).itcount() ); // Check multiple nested array fields. t.drop(); t.save( {a:[[1]]} ); -assert.writeOK(t.ensureIndex( {'a.0.0':1} )); +assert.commandWorked(t.ensureIndex( {'a.0.0':1} )); assert.eq( 1, t.find( {'a.0.0':1} ).hint( {$natural:1} ).itcount() ); assert.eq( 1, t.find( {'a.0.0':1} ).hint( {'a.0.0':1} ).itcount() ); // Check where there is a duplicate for a partially addressed field but not for a fully addressed field. t.drop(); t.save( {a:[[1],{'0':1}]} ); -assert.writeError(t.ensureIndex( {'a.0.0':1} )); +assert.commandFailed(t.ensureIndex( {'a.0.0':1} )); // Check where there is a duplicate for a fully addressed field. t.drop(); assert.writeOK( t.save( {a:[[1],{'0':[1]}]} )); -assert.writeError(t.ensureIndex( {'a.0.0':1} )); +assert.commandFailed(t.ensureIndex( {'a.0.0':1} )); // Two ways of addressing parse to an array. t.drop(); t.save( {a:[{'0':1}]} ); -assert.writeError(t.ensureIndex( {'a.0.0':1} )); +assert.commandFailed(t.ensureIndex( {'a.0.0':1} )); // Test several key depths - with same arrays being found. t.drop(); t.save( {a:[{'0':[{'0':1}]}]} ); -assert.writeError(t.ensureIndex( {'a.0.0.0.0.0.0':1} )); -assert.writeError(t.ensureIndex( {'a.0.0.0.0.0':1} )); -assert.writeError(t.ensureIndex( {'a.0.0.0.0':1} )); -assert.writeError(t.ensureIndex( {'a.0.0.0':1} )); -assert.writeError(t.ensureIndex( {'a.0.0':1} )); -assert.writeError(t.ensureIndex( {'a.0':1} )); -assert.writeOK(t.ensureIndex( {'a':1} )); +assert.commandFailed(t.ensureIndex( {'a.0.0.0.0.0.0':1} )); +assert.commandFailed(t.ensureIndex( {'a.0.0.0.0.0':1} )); +assert.commandFailed(t.ensureIndex( {'a.0.0.0.0':1} )); +assert.commandFailed(t.ensureIndex( {'a.0.0.0':1} )); +assert.commandFailed(t.ensureIndex( {'a.0.0':1} )); +assert.commandFailed(t.ensureIndex( {'a.0':1} )); +assert.commandWorked(t.ensureIndex( {'a':1} )); // Two prefixes extract docs, but one terminates extraction before array. t.drop(); t.save( {a:[{'0':{'c':[]}}]} ); -assert.writeError(t.ensureIndex( {'a.0.c':1} )); +assert.commandFailed(t.ensureIndex( {'a.0.c':1} )); t.drop(); t.save( {a:[[{'b':1}]]} ); diff --git a/jstests/core/long_index_rename.js b/jstests/core/long_index_rename.js index 718d0bd09aa..27517ac8e5a 100644 --- a/jstests/core/long_index_rename.js +++ b/jstests/core/long_index_rename.js @@ -14,4 +14,4 @@ t.createIndex({a:1}, {name: "aaa"}); var result = t.createIndex({a:1}, {name: "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" + "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"}); assert( !result.ok ); -assert( result.getWriteError().errmsg.indexOf( "too long" ) >= 0 ); +assert( result.errmsg.indexOf( "too long" ) >= 0 ); diff --git a/jstests/core/ns_length.js b/jstests/core/ns_length.js index bd69baed222..203e68ead58 100644 --- a/jstests/core/ns_length.js +++ b/jstests/core/ns_length.js @@ -36,7 +36,7 @@ function canMakeCollectionWithName(name) { } function canMakeIndexWithName(collection, name) { - var success = !(collection.ensureIndex({x:1}, {name: name}).hasWriteErrors()); + var success = collection.ensureIndex({x:1}, {name: name}).ok; if (success) { assert.commandWorked(collection.dropIndex(name)); } diff --git a/jstests/core/uniqueness.js b/jstests/core/uniqueness.js index 56107e7ce25..9cde613bbe4 100644 --- a/jstests/core/uniqueness.js +++ b/jstests/core/uniqueness.js @@ -28,8 +28,8 @@ db.jstests_uniqueness2.insert({a:3}); db.jstests_uniqueness2.insert({a:3}); assert( db.jstests_uniqueness2.count() == 2 , 6) ; res = db.jstests_uniqueness2.ensureIndex({a:1}, true); -assert.writeError( res ); -assert( res.getWriteError().errmsg.match( /E11000/ ) ); +assert.commandFailed( res ); +assert( res.errmsg.match( /E11000/ ) ); // Check for an error message when we index in the background and there are dups db.jstests_uniqueness2.drop(); @@ -37,8 +37,8 @@ db.jstests_uniqueness2.insert({a:3}); db.jstests_uniqueness2.insert({a:3}); assert( db.jstests_uniqueness2.count() == 2 , 6) ; res = db.jstests_uniqueness2.ensureIndex({a:1}, {unique:true,background:true}); -assert.writeError( res ); -assert( res.getWriteError().errmsg.match( /E11000/ ) ); +assert.commandFailed( res ); +assert( res.errmsg.match( /E11000/ ) ); /* Check that if we update and remove _id, it gets added back by the DB */ |