diff options
author | Rishab Joshi <rishab.joshi@mongodb.com> | 2020-11-10 13:42:25 +0000 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2020-11-12 10:38:50 +0000 |
commit | e69c967ff8b53634770438dfe9a5c7d13548351b (patch) | |
tree | cf8f6b10b2374f388d51213d172f28b4fd3d05e8 /jstests/core | |
parent | 916c466afac10d34e61b6ca42a12e35d7c4828f1 (diff) | |
download | mongo-e69c967ff8b53634770438dfe9a5c7d13548351b.tar.gz |
SERVER-50442 Remove ensureIndex shell function This commit also replaces all the usages of ensureIndex() with createIndex() in JS tests and JS shell
Diffstat (limited to 'jstests/core')
388 files changed, 910 insertions, 910 deletions
diff --git a/jstests/core/all.js b/jstests/core/all.js index 9d142e6e6c4..a718e2615e8 100644 --- a/jstests/core/all.js +++ b/jstests/core/all.js @@ -39,5 +39,5 @@ doTest = function() { doTest(); t.drop(); -t.ensureIndex({a: 1}); +t.createIndex({a: 1}); doTest(); diff --git a/jstests/core/all2.js b/jstests/core/all2.js index c6b4170a7ff..44462787d20 100644 --- a/jstests/core/all2.js +++ b/jstests/core/all2.js @@ -29,7 +29,7 @@ check(1, {"a.x": {$all: [1, 2]}}, "F"); check(1, {"a.x": {$all: [2, 3]}}, "G"); check(0, {"a.x": {$all: [1, 3]}}, "H"); -t.ensureIndex({"a.x": 1}); +t.createIndex({"a.x": 1}); state = "index"; check(1, {"a.x": {$in: [1]}}, "A"); @@ -64,7 +64,7 @@ check(1, {"a": {$all: [1, 2]}}, "F"); check(1, {"a": {$all: [2, 3]}}, "G"); check(0, {"a": {$all: [1, 3]}}, "H"); -t.ensureIndex({"a": 1}); +t.createIndex({"a": 1}); state = "more index"; check(1, {"a": {$in: [1]}}, "A"); @@ -85,5 +85,5 @@ state = "more 2"; t.drop(); t.save({name: ["harry", "jack", "tom"]}); check(0, {name: {$all: ["harry", "john"]}}, "A"); -t.ensureIndex({name: 1}); +t.createIndex({name: 1}); check(0, {name: {$all: ["harry", "john"]}}, "B"); diff --git a/jstests/core/and.js b/jstests/core/and.js index 389aaa8d1d1..20fd583c31f 100644 --- a/jstests/core/and.js +++ b/jstests/core/and.js @@ -77,7 +77,7 @@ function check() { } check(); -t.ensureIndex({a: 1}); +t.createIndex({a: 1}); check(); assert.eq(1, t.find({a: 1, $and: [{a: 2}]}).itcount()); diff --git a/jstests/core/and3.js b/jstests/core/and3.js index 6fd8e63d910..1e74db57594 100644 --- a/jstests/core/and3.js +++ b/jstests/core/and3.js @@ -12,7 +12,7 @@ t.drop(); t.save({a: 1}); t.save({a: 'foo'}); -t.ensureIndex({a: 1}); +t.createIndex({a: 1}); function checkScanMatch(query, docsExamined, n) { var e = t.find(query).hint({a: 1}).explain("executionStats"); diff --git a/jstests/core/andor.js b/jstests/core/andor.js index e5e665ec398..5bac12d83ca 100644 --- a/jstests/core/andor.js +++ b/jstests/core/andor.js @@ -47,7 +47,7 @@ test = function() { }; test(); -t.ensureIndex({a: 1}); +t.createIndex({a: 1}); test(); // Test an inequality base match. @@ -91,5 +91,5 @@ test = function() { t.drop(); t.save({a: 1}); test(); -t.ensureIndex({a: 1}); +t.createIndex({a: 1}); test(); diff --git a/jstests/core/apitest_dbcollection.js b/jstests/core/apitest_dbcollection.js index 9bdbb8d0f91..00f9b6b4c4c 100644 --- a/jstests/core/apitest_dbcollection.js +++ b/jstests/core/apitest_dbcollection.js @@ -99,7 +99,7 @@ assert.eq(0, db.getCollection("test_db").getIndexes().length, "13"); db.getCollection("test_db").save({a: 10}); assert.eq(1, db.getCollection("test_db").getIndexes().length, "14"); -db.getCollection("test_db").ensureIndex({a: 1}); +db.getCollection("test_db").createIndex({a: 1}); db.getCollection("test_db").save({a: 10}); print(tojson(db.getCollection("test_db").getIndexes())); @@ -109,7 +109,7 @@ db.getCollection("test_db").dropIndex({a: 1}); assert.eq(1, db.getCollection("test_db").getIndexes().length, "16"); db.getCollection("test_db").save({a: 10}); -db.getCollection("test_db").ensureIndex({a: 1}); +db.getCollection("test_db").createIndex({a: 1}); db.getCollection("test_db").save({a: 10}); assert.eq(2, db.getCollection("test_db").getIndexes().length, "17"); @@ -118,8 +118,8 @@ db.getCollection("test_db").dropIndex("a_1"); assert.eq(1, db.getCollection("test_db").getIndexes().length, "18"); db.getCollection("test_db").save({a: 10, b: 11}); -db.getCollection("test_db").ensureIndex({a: 1}); -db.getCollection("test_db").ensureIndex({b: 1}); +db.getCollection("test_db").createIndex({a: 1}); +db.getCollection("test_db").createIndex({b: 1}); db.getCollection("test_db").save({a: 10, b: 12}); assert.eq(3, db.getCollection("test_db").getIndexes().length, "19"); @@ -130,8 +130,8 @@ db.getCollection("test_db").dropIndex({a: 1}); assert.eq(1, db.getCollection("test_db").getIndexes().length, "21"); db.getCollection("test_db").save({a: 10, b: 11}); -db.getCollection("test_db").ensureIndex({a: 1}); -db.getCollection("test_db").ensureIndex({b: 1}); +db.getCollection("test_db").createIndex({a: 1}); +db.getCollection("test_db").createIndex({b: 1}); db.getCollection("test_db").save({a: 10, b: 12}); assert.eq(3, db.getCollection("test_db").getIndexes().length, "22"); @@ -179,7 +179,7 @@ assert.eq(10, // indexDetails - If true, includes 'indexDetails' field in results. Default: false. t.drop(); t.save({a: 1}); -t.ensureIndex({a: 1}); +t.createIndex({a: 1}); collectionStats = assert.commandWorked(t.stats()); assert(!collectionStats.hasOwnProperty('indexDetails'), 'unexpected indexDetails found in db.collection.stats() result: ' + tojson(collectionStats)); diff --git a/jstests/core/array1.js b/jstests/core/array1.js index 27addaed616..d25b609f3d3 100644 --- a/jstests/core/array1.js +++ b/jstests/core/array1.js @@ -14,6 +14,6 @@ assert.eq(1, coll.find(x).count()); assert.commandWorked(coll.insert(x)); assert.eq(2, coll.find(x).count()); -assert.commandWorked(coll.ensureIndex({a: 1})); +assert.commandWorked(coll.createIndex({a: 1})); assert.eq(2, coll.find(x).count()); }()); diff --git a/jstests/core/array_match1.js b/jstests/core/array_match1.js index b6a0930968e..0c56e8d4c34 100644 --- a/jstests/core/array_match1.js +++ b/jstests/core/array_match1.js @@ -16,7 +16,7 @@ function test(f, m) { } test("a", "A"); -t.ensureIndex({a: 1}); +t.createIndex({a: 1}); test("a", "B"); t.drop(); @@ -26,5 +26,5 @@ t.insert({_id: 2, a: {b: [6, 6]}}); t.insert({_id: 3, a: {b: [5, 5]}}); test("a.b", "C"); -t.ensureIndex({a: 1}); +t.createIndex({a: 1}); test("a.b", "D"); diff --git a/jstests/core/array_match3.js b/jstests/core/array_match3.js index 837341afc8a..4990bdd90fd 100644 --- a/jstests/core/array_match3.js +++ b/jstests/core/array_match3.js @@ -9,5 +9,5 @@ t.save({a: [5]}); assert.eq(2, t.count({'a.0': 5})); // Test with index. -t.ensureIndex({'a.0': 1}); +t.createIndex({'a.0': 1}); assert.eq(2, t.count({'a.0': 5})); diff --git a/jstests/core/array_match4.js b/jstests/core/array_match4.js index 821e9a4f4eb..54581a14b97 100644 --- a/jstests/core/array_match4.js +++ b/jstests/core/array_match4.js @@ -16,7 +16,7 @@ assert.eq(1, t.find(query_gte).itcount(), '$gte (without index)'); // with index // -t.ensureIndex({a: 1}); +t.createIndex({a: 1}); assert.eq(1, t.find({a: [1, 2]}).count(), '$eq (with index)'); // display explain output (for index bounds) diff --git a/jstests/core/arrayfind1.js b/jstests/core/arrayfind1.js index c9d75c17f65..4e9330549ae 100644 --- a/jstests/core/arrayfind1.js +++ b/jstests/core/arrayfind1.js @@ -26,7 +26,7 @@ t.save({a: [{x: 4}]}); assert.eq(1, t.find({a: {$elemMatch: {x: 2}}}).count(), "B1"); assert.eq(2, t.find({a: {$elemMatch: {x: {$gt: 2}}}}).count(), "B2"); -t.ensureIndex({"a.x": 1}); +t.createIndex({"a.x": 1}); assert.eq(1, t.find({a: {$elemMatch: {x: 2}}}).count(), "D1"); assert.eq(3, t.find({"a.x": 1}).count(), "D2.1"); assert.eq(3, t.find({"a.x": {$gt: 1}}).count(), "D2.2"); diff --git a/jstests/core/arrayfind2.js b/jstests/core/arrayfind2.js index bbceffaa126..38de844f6f4 100644 --- a/jstests/core/arrayfind2.js +++ b/jstests/core/arrayfind2.js @@ -25,5 +25,5 @@ t.save({a: [{x: 3}, {x: 5}]}); t.save({a: [{x: 3}, {x: 6}]}); go("no index"); -t.ensureIndex({a: 1}); +t.createIndex({a: 1}); go("index(a)"); diff --git a/jstests/core/arrayfind3.js b/jstests/core/arrayfind3.js index 312ae4c0349..6dba0bf625f 100644 --- a/jstests/core/arrayfind3.js +++ b/jstests/core/arrayfind3.js @@ -8,7 +8,7 @@ t.save({a: [1, 4, 6]}); assert.eq(2, t.find({a: {$gte: 3, $lte: 5}}).itcount(), "A1"); assert.eq(1, t.find({a: {$elemMatch: {$gte: 3, $lte: 5}}}).itcount(), "A2"); -t.ensureIndex({a: 1}); +t.createIndex({a: 1}); assert.eq(2, t.find({a: {$gte: 3, $lte: 5}}).itcount(), "B1"); assert.eq(1, t.find({a: {$elemMatch: {$gte: 3, $lte: 5}}}).itcount(), "B2"); diff --git a/jstests/core/arrayfind4.js b/jstests/core/arrayfind4.js index 4fac0b63755..2d7c0e03668 100644 --- a/jstests/core/arrayfind4.js +++ b/jstests/core/arrayfind4.js @@ -8,7 +8,7 @@ t = db.jstests_arrayfind4; t.drop(); t.save({a: []}); -t.ensureIndex({a: 1}); +t.createIndex({a: 1}); assert.eq(1, t.find({a: []}).hint({$natural: 1}).itcount()); assert.eq(1, t.find({a: []}).hint({a: 1}).itcount()); diff --git a/jstests/core/arrayfind5.js b/jstests/core/arrayfind5.js index 9f8800a0c69..171fe49e1f8 100644 --- a/jstests/core/arrayfind5.js +++ b/jstests/core/arrayfind5.js @@ -16,12 +16,12 @@ function check(nullElemMatch) { t.save({a: [{}, {b: 1}]}); check(true); -t.ensureIndex({'a.b': 1}); +t.createIndex({'a.b': 1}); check(true); t.drop(); t.save({a: [5, {b: 1}]}); check(false); -t.ensureIndex({'a.b': 1}); +t.createIndex({'a.b': 1}); check(false); diff --git a/jstests/core/arrayfind6.js b/jstests/core/arrayfind6.js index f01271b6673..bd91859c9dc 100644 --- a/jstests/core/arrayfind6.js +++ b/jstests/core/arrayfind6.js @@ -17,5 +17,5 @@ function checkElemMatchMatches() { } checkElemMatchMatches(); -t.ensureIndex({'a.b': 1}); +t.createIndex({'a.b': 1}); checkElemMatchMatches(); diff --git a/jstests/core/arrayfind7.js b/jstests/core/arrayfind7.js index 699f8c9586d..be2061c5c0d 100644 --- a/jstests/core/arrayfind7.js +++ b/jstests/core/arrayfind7.js @@ -11,7 +11,7 @@ function checkElemMatchMatches() { // The document is matched using nested $elemMatch expressions, with and without an index. checkElemMatchMatches(); -t.ensureIndex({'a.b.c': 1}); +t.createIndex({'a.b.c': 1}); checkElemMatchMatches(); function checkElemMatch(index, document, query) { @@ -19,7 +19,7 @@ function checkElemMatch(index, document, query) { t.drop(); t.save(document); assert.eq(1, t.count(query)); - t.ensureIndex(index); + t.createIndex(index); assert.eq(1, t.count(query)); t.save({a: {b: {c: [10, 11]}}}); // Make the index multikey. assert.eq(1, t.count(query)); diff --git a/jstests/core/arrayfind9.js b/jstests/core/arrayfind9.js index 98396701dce..5406ae8c1d1 100644 --- a/jstests/core/arrayfind9.js +++ b/jstests/core/arrayfind9.js @@ -25,8 +25,8 @@ assert.eq(1, t.count({a: {$elemMatch: {'0': 'x'}}})); // Matching multiple values of a nested array. t.drop(); t.save({a: [{b: [0, 2]}]}); -t.ensureIndex({a: 1}); -t.ensureIndex({'a.b': 1}); +t.createIndex({a: 1}); +t.createIndex({'a.b': 1}); plans = [{$natural: 1}, {a: 1}, {'a.b': 1}]; for (i in plans) { p = plans[i]; diff --git a/jstests/core/arrayfinda.js b/jstests/core/arrayfinda.js index f2939d0c1ba..163af3d8d29 100644 --- a/jstests/core/arrayfinda.js +++ b/jstests/core/arrayfinda.js @@ -16,6 +16,6 @@ assertExpectedMatch(t.find({a: {$elemMatch: {b: {$gte: 1}}}})); assertExpectedMatch(t.find({a: {$elemMatch: {b: 1}}})); // $elemMatch is not used to perform key matching. SERVER-6001 -t.ensureIndex({a: 1}); +t.createIndex({a: 1}); assertExpectedMatch(t.find({a: {$elemMatch: {b: {$gte: 1}}}}).hint({a: 1})); assertExpectedMatch(t.find({a: {$elemMatch: {b: 1}}}).hint({a: 1})); diff --git a/jstests/core/arrayfindb.js b/jstests/core/arrayfindb.js index c9456509487..7277f51c4f4 100644 --- a/jstests/core/arrayfindb.js +++ b/jstests/core/arrayfindb.js @@ -12,7 +12,7 @@ assert.eq(0, t.find({a: {$elemMatch: {b: {$gte: 2, $lt: 4}, c: 25}}}).itcount(), "Case #1: wrong number of results returned -- unindexed"); -t.ensureIndex({"a.b": 1, "a.c": 1}); +t.createIndex({"a.b": 1, "a.c": 1}); assert.eq(0, t.find({a: {$elemMatch: {b: {$gte: 2, $lt: 4}, c: 25}}}).itcount(), "Case #1: wrong number of results returned -- indexed"); @@ -26,8 +26,8 @@ assert.eq(2, t.find({a: {$elemMatch: {$or: [{b: 2}, {c: 2}]}}}).itcount(), "Case #2: wrong number of results returned -- unindexed"); -t.ensureIndex({"a.b": 1}); -t.ensureIndex({"a.c": 1}); +t.createIndex({"a.b": 1}); +t.createIndex({"a.c": 1}); assert.eq(2, t.find({a: {$elemMatch: {$or: [{b: 2}, {c: 2}]}}}).itcount(), "Case #2: wrong number of results returned -- indexed"); diff --git a/jstests/core/bad_index_plugin.js b/jstests/core/bad_index_plugin.js index 7ecfe76c198..c9cd549cc03 100644 --- a/jstests/core/bad_index_plugin.js +++ b/jstests/core/bad_index_plugin.js @@ -1,10 +1,10 @@ // SERVER-5826 ensure you can't build an index with a non-existent plugin t = db.bad_index_plugin; -assert.commandWorked(t.ensureIndex({good: 1})); +assert.commandWorked(t.createIndex({good: 1})); assert.eq(t.getIndexes().length, 2); // good + _id -var err = t.ensureIndex({bad: 'bad'}); +var err = t.createIndex({bad: 'bad'}); assert.commandFailed(err); assert(err.code >= 0); diff --git a/jstests/core/basic7.js b/jstests/core/basic7.js index bfe82ccda17..dc6f18cc95b 100644 --- a/jstests/core/basic7.js +++ b/jstests/core/basic7.js @@ -3,7 +3,7 @@ t = db.basic7; t.drop(); t.save({a: 1}); -t.ensureIndex({a: 1}); +t.createIndex({a: 1}); assert.eq(t.find().toArray()[0].a, 1); assert.eq(t.find().arrayAccess(0).a, 1); diff --git a/jstests/core/batch_size.js b/jstests/core/batch_size.js index 11ea9cd2380..c0afc382975 100644 --- a/jstests/core/batch_size.js +++ b/jstests/core/batch_size.js @@ -46,7 +46,7 @@ assert.eq(1, t.find().batchSize(-1).itcount()); assert.eq(2, t.find().batchSize(-2).itcount()); // Run the tests with the index twice in order to double check plan caching. -t.ensureIndex({a: 1}); +t.createIndex({a: 1}); for (var i = 0; i < 2; i++) { runIndexedTests(); } @@ -54,8 +54,8 @@ for (var i = 0; i < 2; i++) { // The next tests make sure that we obey limit and batchSize properly when the sort could be // either indexed or unindexed. t.drop(); -t.ensureIndex({a: 1}); -t.ensureIndex({b: 1}); +t.createIndex({a: 1}); +t.createIndex({b: 1}); for (var i = 0; i < 100; i++) { t.save({_id: i, a: i, b: 1}); @@ -118,8 +118,8 @@ for (var i = 0; i < nDocs; i++) { } // Two indices needed in order to trigger plan ranking. Neither index provides the sort order. -t.ensureIndex({x: 1}); -t.ensureIndex({y: 1}); +t.createIndex({x: 1}); +t.createIndex({y: 1}); // We should only buffer 3 docs in memory. var cursor = t.find({x: 1, y: 1}).sort({z: -1}).limit(3); diff --git a/jstests/core/batch_write_command_insert.js b/jstests/core/batch_write_command_insert.js index cf1b0013ef7..664ff73958a 100644 --- a/jstests/core/batch_write_command_insert.js +++ b/jstests/core/batch_write_command_insert.js @@ -179,7 +179,7 @@ assert(resultNOK(result), tojson(result)); // // Should fail single insert due to duplicate key coll.drop(); -coll.ensureIndex({a: 1}, {unique: true}); +coll.createIndex({a: 1}, {unique: true}); coll.insert({a: 1}); request = { insert: coll.getName(), @@ -194,7 +194,7 @@ assert.eq(coll.count(), 1); // // Fail with duplicate key error on multiple document inserts, ordered false coll.drop(); -coll.ensureIndex({a: 1}, {unique: true}); +coll.createIndex({a: 1}, {unique: true}); request = { insert: coll.getName(), documents: [{a: 1}, {a: 1}, {a: 1}], @@ -220,7 +220,7 @@ assert.eq(coll.count(), 1); // // Fail with duplicate key error on multiple document inserts, ordered true coll.drop(); -coll.ensureIndex({a: 1}, {unique: true}); +coll.createIndex({a: 1}, {unique: true}); request = { insert: coll.getName(), documents: [{a: 1}, {a: 1}, {a: 1}], @@ -241,7 +241,7 @@ assert.eq(coll.count(), 1); // // Ensure _id is the first field in all documents coll.drop(); -coll.ensureIndex({a: 1}, {unique: true}); +coll.createIndex({a: 1}, {unique: true}); request = { insert: coll.getName(), documents: [{a: 1}, {a: 2, _id: 2}] diff --git a/jstests/core/batch_write_command_update.js b/jstests/core/batch_write_command_update.js index edb90be8523..f6372a651af 100644 --- a/jstests/core/batch_write_command_update.js +++ b/jstests/core/batch_write_command_update.js @@ -235,7 +235,7 @@ assert.eq(1, coll.count()); // // Upsert fail due to duplicate key index, w:1, ordered:true coll.drop(); -coll.ensureIndex({a: 1}, {unique: true}); +coll.createIndex({a: 1}, {unique: true}); request = { update: coll.getName(), updates: [ @@ -266,7 +266,7 @@ assert.eq(1, coll.count({_id: result.upserted[1]._id})); // // Upsert fail due to duplicate key index, w:1, ordered:false coll.drop(); -coll.ensureIndex({a: 1}, {unique: true}); +coll.createIndex({a: 1}, {unique: true}); request = { update: coll.getName(), updates: [ diff --git a/jstests/core/batch_write_command_w0.js b/jstests/core/batch_write_command_w0.js index 01b9cb5f165..ca2522bbe01 100644 --- a/jstests/core/batch_write_command_w0.js +++ b/jstests/core/batch_write_command_w0.js @@ -76,7 +76,7 @@ countEventually(coll, 2); // // Upsert fail due to duplicate key index, w:0, ordered:true coll.drop(); -coll.ensureIndex({a: 1}, {unique: true}); +coll.createIndex({a: 1}, {unique: true}); request = { update: coll.getName(), updates: [ diff --git a/jstests/core/bulk_api_ordered.js b/jstests/core/bulk_api_ordered.js index 2957195065d..d3a484c2b12 100644 --- a/jstests/core/bulk_api_ordered.js +++ b/jstests/core/bulk_api_ordered.js @@ -80,7 +80,7 @@ var executeTests = function() { // Create unique index coll.remove({}); - coll.ensureIndex({a: 1}, {unique: true}); + coll.createIndex({a: 1}, {unique: true}); /** * Single error ordered bulk operation @@ -118,7 +118,7 @@ var executeTests = function() { // Create unique index coll.dropIndexes(); coll.remove({}); - coll.ensureIndex({a: 1}, {unique: true}); + coll.createIndex({a: 1}, {unique: true}); /** * Multiple error ordered bulk operation @@ -152,7 +152,7 @@ var executeTests = function() { // Create unique index coll.dropIndexes(); coll.remove({}); - coll.ensureIndex({a: 1}, {unique: true}); + coll.createIndex({a: 1}, {unique: true}); }; var buildVersion = parseInt(db.runCommand({buildInfo: 1}).versionArray.slice(0, 3).join(""), 10); diff --git a/jstests/core/bulk_api_unordered.js b/jstests/core/bulk_api_unordered.js index 6db2a607a25..04e002306e5 100644 --- a/jstests/core/bulk_api_unordered.js +++ b/jstests/core/bulk_api_unordered.js @@ -85,7 +85,7 @@ var executeTests = function() { // Create unique index coll.remove({}); - coll.ensureIndex({a: 1}, {unique: true}); + coll.createIndex({a: 1}, {unique: true}); /** * Single error unordered bulk operation @@ -118,7 +118,7 @@ var executeTests = function() { // Create unique index coll.dropIndexes(); coll.remove({}); - coll.ensureIndex({a: 1}, {unique: true}); + coll.createIndex({a: 1}, {unique: true}); /** * Multiple error unordered bulk operation @@ -168,7 +168,7 @@ var executeTests = function() { // Create unique index coll.dropIndexes(); coll.remove({}); - coll.ensureIndex({a: 1}, {unique: true}); + coll.createIndex({a: 1}, {unique: true}); }; var buildVersion = parseInt(db.runCommand({buildInfo: 1}).versionArray.slice(0, 3).join(""), 10); diff --git a/jstests/core/capped5.js b/jstests/core/capped5.js index 0efb957ae6c..163aa684fbe 100644 --- a/jstests/core/capped5.js +++ b/jstests/core/capped5.js @@ -9,8 +9,8 @@ t.insert({_id: 5, x: 11, z: 52}); assert.eq(1, t.getIndexKeys().length, "A0"); // now we assume _id index even on capped coll assert.eq(52, t.findOne({x: 11}).z, "A1"); -t.ensureIndex({_id: 1}); -t.ensureIndex({x: 1}); +t.createIndex({_id: 1}); +t.createIndex({x: 1}); assert.eq(52, t.findOne({x: 11}).z, "B1"); assert.eq(52, t.findOne({_id: 5}).z, "B2"); @@ -26,14 +26,14 @@ t.drop(); db.createCollection(tn, {capped: true, size: 1024 * 1024 * 1}); t.insert({_id: 5, x: 11}); t.insert({_id: 6, x: 12}); -t.ensureIndex({x: 1}, {unique: true}); +t.createIndex({x: 1}, {unique: true}); assert.eq(2, t.getIndexes().length); // now we assume _id index assert.eq(2, t.find().hint({x: 1}).toArray().length); // SERVER-525 (closed) unique indexes in capped collection t.drop(); db.createCollection(tn, {capped: true, size: 1024 * 1024 * 1}); -t.ensureIndex({_id: 1}); // note we assume will be automatically unique because it is _id +t.createIndex({_id: 1}); // note we assume will be automatically unique because it is _id t.insert({_id: 5, x: 11}); t.insert({_id: 5, x: 12}); assert.eq(1, t.find().toArray().length); diff --git a/jstests/core/capped_empty.js b/jstests/core/capped_empty.js index 99e08f217ed..93657b4a67f 100644 --- a/jstests/core/capped_empty.js +++ b/jstests/core/capped_empty.js @@ -14,7 +14,7 @@ db.createCollection(t.getName(), {capped: true, size: 100}); t.insert({x: 1}); t.insert({x: 2}); t.insert({x: 3}); -t.ensureIndex({x: 1}); +t.createIndex({x: 1}); assert.eq(3, t.count()); diff --git a/jstests/core/cappeda.js b/jstests/core/cappeda.js index f506d5416b1..1061ba0a1d6 100644 --- a/jstests/core/cappeda.js +++ b/jstests/core/cappeda.js @@ -22,7 +22,7 @@ function u() { // assert.throws( q , [] , "A1" ); // assert.throws( u , [] , "B1" ); -t.ensureIndex({_id: 1}); +t.createIndex({_id: 1}); assert.eq(1, q().x); q(); diff --git a/jstests/core/check_shard_index.js b/jstests/core/check_shard_index.js index f187a6210d0..e64beee77f8 100644 --- a/jstests/core/check_shard_index.js +++ b/jstests/core/check_shard_index.js @@ -16,7 +16,7 @@ f.drop(); // f.drop(); -f.ensureIndex({x: 1, y: 1}); +f.createIndex({x: 1, y: 1}); assert.eq(0, f.count(), "1. initial count should be zero"); res = db.runCommand({checkShardingIndex: "test.jstests_shardingindex", keyPattern: {x: 1, y: 1}}); @@ -32,7 +32,7 @@ assert.eq(true, res.ok, "1b"); // f.drop(); -f.ensureIndex({x: 1, y: 1}); +f.createIndex({x: 1, y: 1}); assert.eq(0, f.count(), "2. initial count should be zero"); f.save({x: 1, y: 1}); @@ -56,7 +56,7 @@ assert(res.idskip, "2d " + tojson(res)); // f.drop(); -f.ensureIndex({x: 1, y: 1}); +f.createIndex({x: 1, y: 1}); assert.eq(0, f.count(), "3. initial count should be zero"); f.save({x: 1, y: 1}); @@ -68,7 +68,7 @@ assert.eq(false, res.ok, "3a " + tojson(res)); f.remove({y: 2}); f.dropIndex({x: 1, y: 1}); -f.ensureIndex({x: 1, y: 1}); +f.createIndex({x: 1, y: 1}); assert.eq(1, f.count(), "3. count after removing array value should be 1"); res = db.runCommand({checkShardingIndex: "test.jstests_shardingindex", keyPattern: {x: 1, y: 1}}); @@ -85,7 +85,7 @@ assert.eq(false, res.ok, "3c " + tojson(res)); // f.drop(); -f.ensureIndex({x: 1, y: 1, z: 1}); +f.createIndex({x: 1, y: 1, z: 1}); assert.eq(0, f.count(), "4. initial count should be zero"); f.save({x: 1, y: 1, z: 1}); @@ -110,7 +110,7 @@ assert.eq(false, res.ok, "4e " + tojson(res)); f.remove({y: 2}); f.dropIndex({x: 1, y: 1, z: 1}); -f.ensureIndex({x: 1, y: 1, z: 1}); +f.createIndex({x: 1, y: 1, z: 1}); assert.eq(1, f.count(), "4. count after removing array value should be 1"); res = db.runCommand( @@ -131,7 +131,7 @@ assert.eq(false, res.ok, "4i " + tojson(res)); f.remove({x: 3}); // Necessary so that the index is no longer marked as multikey f.dropIndex({x: 1, y: 1, z: 1}); -f.ensureIndex({x: 1, y: 1, z: 1}); +f.createIndex({x: 1, y: 1, z: 1}); assert.eq(1, f.count(), "4. count after removing array value should be 1 again"); res = db.runCommand( diff --git a/jstests/core/collation.js b/jstests/core/collation.js index 5cfedcc8e1f..44e8092f75e 100644 --- a/jstests/core/collation.js +++ b/jstests/core/collation.js @@ -99,7 +99,7 @@ assert.eq(collectionInfos[0].options.collation, { }); // Ensure that an index with no collation inherits the collection-default collation. -assert.commandWorked(coll.ensureIndex({a: 1})); +assert.commandWorked(coll.createIndex({a: 1})); assertIndexHasCollation({a: 1}, { locale: "fr_CA", caseLevel: false, @@ -115,7 +115,7 @@ assertIndexHasCollation({a: 1}, { // Ensure that an index which specifies an overriding collation does not use the collection // default. -assert.commandWorked(coll.ensureIndex({b: 1}, {collation: {locale: "en_US"}})); +assert.commandWorked(coll.createIndex({b: 1}, {collation: {locale: "en_US"}})); assertIndexHasCollation({b: 1}, { locale: "en_US", caseLevel: false, @@ -131,11 +131,11 @@ assertIndexHasCollation({b: 1}, { // Ensure that an index which specifies the "simple" collation as an overriding collation still // does not use the collection default. -assert.commandWorked(coll.ensureIndex({d: 1}, {collation: {locale: "simple"}})); +assert.commandWorked(coll.createIndex({d: 1}, {collation: {locale: "simple"}})); assertIndexHasCollation({d: 1}, {locale: "simple"}); // Ensure that a v=1 index doesn't inherit the collection-default collation. -assert.commandWorked(coll.ensureIndex({c: 1}, {v: 1})); +assert.commandWorked(coll.createIndex({c: 1}, {v: 1})); assertIndexHasCollation({c: 1}, {locale: "simple"}); // Test that all indexes retain their current collation when the collection is re-indexed. (Only @@ -177,20 +177,20 @@ coll.drop(); // // Attempting to build an index with an invalid collation should fail. -assert.commandFailed(coll.ensureIndex({a: 1}, {collation: "not an object"})); -assert.commandFailed(coll.ensureIndex({a: 1}, {collation: {}})); -assert.commandFailed(coll.ensureIndex({a: 1}, {collation: {blah: 1}})); -assert.commandFailed(coll.ensureIndex({a: 1}, {collation: {locale: "en", blah: 1}})); -assert.commandFailed(coll.ensureIndex({a: 1}, {collation: {locale: "xx"}})); -assert.commandFailed(coll.ensureIndex({a: 1}, {collation: {locale: "en", strength: 99}})); +assert.commandFailed(coll.createIndex({a: 1}, {collation: "not an object"})); +assert.commandFailed(coll.createIndex({a: 1}, {collation: {}})); +assert.commandFailed(coll.createIndex({a: 1}, {collation: {blah: 1}})); +assert.commandFailed(coll.createIndex({a: 1}, {collation: {locale: "en", blah: 1}})); +assert.commandFailed(coll.createIndex({a: 1}, {collation: {locale: "xx"}})); +assert.commandFailed(coll.createIndex({a: 1}, {collation: {locale: "en", strength: 99}})); // Attempting to create an index whose collation version does not match the collator version // produced by ICU should result in failure with a special error code. assert.commandFailedWithCode( - coll.ensureIndex({a: 1}, {collation: {locale: "en", version: "unknownVersion"}}), + coll.createIndex({a: 1}, {collation: {locale: "en", version: "unknownVersion"}}), ErrorCodes.IncompatibleCollationVersion); -assert.commandWorked(coll.ensureIndex({a: 1}, {collation: {locale: "en_US"}})); +assert.commandWorked(coll.createIndex({a: 1}, {collation: {locale: "en_US"}})); assertIndexHasCollation({a: 1}, { locale: "en_US", caseLevel: false, @@ -335,7 +335,7 @@ assert.eq(0, coll.aggregate([{$match: {str: "FOO"}}], {collation: {locale: "simp // default collation. coll.drop(); assert.commandWorked(db.createCollection(coll.getName(), {collation: {locale: "en_US"}})); -assert.commandWorked(coll.ensureIndex({a: 1}, {collation: {locale: "en_US"}})); +assert.commandWorked(coll.createIndex({a: 1}, {collation: {locale: "en_US"}})); var explain = coll.explain("queryPlanner").aggregate([{$match: {a: "foo"}}]); assert(isIxscan(db, explain.queryPlanner.winningPlan)); @@ -343,7 +343,7 @@ assert(isIxscan(db, explain.queryPlanner.winningPlan)); // collation is incompatible with index collation. coll.drop(); assert.commandWorked(db.createCollection(coll.getName(), {collation: {locale: "en_US"}})); -assert.commandWorked(coll.ensureIndex({a: 1}, {collation: {locale: "simple"}})); +assert.commandWorked(coll.createIndex({a: 1}, {collation: {locale: "simple"}})); var explain = coll.explain("queryPlanner").aggregate([{$match: {a: "foo"}}]); assert(isCollscan(db, explain.queryPlanner.winningPlan)); @@ -505,7 +505,7 @@ assert.eq(1, coll.distinct("_id", {str: "foo"}, {collation: {locale: "simple"}}) // default collation. coll.drop(); assert.commandWorked(db.createCollection(coll.getName(), {collation: {locale: "en_US"}})); -assert.commandWorked(coll.ensureIndex({a: 1}, {collation: {locale: "en_US"}})); +assert.commandWorked(coll.createIndex({a: 1}, {collation: {locale: "en_US"}})); var explain = coll.explain("queryPlanner").distinct("a"); assert(planHasStage(db, explain.queryPlanner.winningPlan, "DISTINCT_SCAN")); assert(planHasStage(db, explain.queryPlanner.winningPlan, "FETCH")); @@ -534,7 +534,7 @@ assert(!planHasStage(db, explain.queryPlanner.winningPlan, "FETCH")); // incompatible with index collation. coll.drop(); assert.commandWorked(db.createCollection(coll.getName(), {collation: {locale: "en_US"}})); -assert.commandWorked(coll.ensureIndex({a: 1}, {collation: {locale: "simple"}})); +assert.commandWorked(coll.createIndex({a: 1}, {collation: {locale: "simple"}})); var explain = coll.explain("queryPlanner").distinct("a"); assert(isCollscan(db, explain.queryPlanner.winningPlan)); @@ -608,7 +608,7 @@ if (db.getMongo().useReadCommands()) { coll.find({str: {$ne: "FOO"}}).collation({locale: "en_US", strength: 2}).itcount()); // Find should return correct results when collation specified and compatible index exists. - assert.commandWorked(coll.ensureIndex({str: 1}, {collation: {locale: "en_US", strength: 2}})); + assert.commandWorked(coll.createIndex({str: 1}, {collation: {locale: "en_US", strength: 2}})); assert.eq(0, coll.find({str: "FOO"}).hint({str: 1}).itcount()); assert.eq(0, coll.find({str: "FOO"}).collation({locale: "en_US"}).hint({str: 1}).itcount()); assert.eq( @@ -623,7 +623,7 @@ if (db.getMongo().useReadCommands()) { // Find should return correct results when collation specified and compatible partial index // exists. - assert.commandWorked(coll.ensureIndex({str: 1}, { + assert.commandWorked(coll.createIndex({str: 1}, { partialFilterExpression: {str: {$lte: "FOO"}}, collation: {locale: "en_US", strength: 2} })); @@ -644,7 +644,7 @@ if (db.getMongo().useReadCommands()) { // Ensure results from an index that doesn't match the query collation are sorted to match // the requested collation. - assert.commandWorked(coll.ensureIndex({a: 1})); + assert.commandWorked(coll.createIndex({a: 1})); var res = coll.find({a: {'$exists': true}}, {_id: 0}).collation({locale: "en_US", strength: 3}).sort({ a: 1 @@ -746,7 +746,7 @@ if (db.getMongo().useReadCommands()) { // collation. coll.drop(); assert.commandWorked(db.createCollection(coll.getName(), {collation: {locale: "en_US"}})); -assert.commandWorked(coll.ensureIndex({a: 1}, {collation: {locale: "en_US"}})); +assert.commandWorked(coll.createIndex({a: 1}, {collation: {locale: "en_US"}})); var explain = coll.find({a: "foo"}).explain("queryPlanner"); assert(isIxscan(db, explain.queryPlanner.winningPlan)); @@ -754,7 +754,7 @@ assert(isIxscan(db, explain.queryPlanner.winningPlan)); // collation is "simple". coll.drop(); assert.commandWorked(db.createCollection(coll.getName(), {collation: {locale: "simple"}})); -assert.commandWorked(coll.ensureIndex({a: 1}, {collation: {locale: "simple"}})); +assert.commandWorked(coll.createIndex({a: 1}, {collation: {locale: "simple"}})); var explain = coll.find({a: "foo"}).explain("queryPlanner"); assert(isIxscan(db, explain.queryPlanner.winningPlan)); @@ -762,7 +762,7 @@ assert(isIxscan(db, explain.queryPlanner.winningPlan)); // collection has a non-"simple" default collation. coll.drop(); assert.commandWorked(db.createCollection(coll.getName(), {collation: {locale: "en_US"}})); -assert.commandWorked(coll.ensureIndex({a: 1}, {collation: {locale: "simple"}})); +assert.commandWorked(coll.createIndex({a: 1}, {collation: {locale: "simple"}})); var explain = coll.find({a: "foo"}).explain("queryPlanner"); assert(isCollscan(db, explain.queryPlanner.winningPlan)); @@ -770,7 +770,7 @@ assert(isCollscan(db, explain.queryPlanner.winningPlan)); // non-"simple" default collation. coll.drop(); assert.commandWorked(db.createCollection(coll.getName(), {collation: {locale: "en_US"}})); -assert.commandWorked(coll.ensureIndex({a: 1}, {collation: {locale: "simple"}})); +assert.commandWorked(coll.createIndex({a: 1}, {collation: {locale: "simple"}})); var explain = coll.find({a: "foo"}).collation({locale: "simple"}).explain("queryPlanner"); assert(isIxscan(db, explain.queryPlanner.winningPlan)); @@ -1314,14 +1314,14 @@ const geoNearStage = { // $geoNear should return correct results when collation specified and string predicate not // indexed. -assert.commandWorked(coll.ensureIndex({geo: "2dsphere"})); +assert.commandWorked(coll.createIndex({geo: "2dsphere"})); assert.eq(0, coll.aggregate([geoNearStage]).itcount()); assert.eq(1, coll.aggregate([geoNearStage], {collation: {locale: "en_US", strength: 2}}).itcount()); // $geoNear should return correct results when no collation specified and string predicate // indexed. assert.commandWorked(coll.dropIndexes()); -assert.commandWorked(coll.ensureIndex({geo: "2dsphere", str: 1})); +assert.commandWorked(coll.createIndex({geo: "2dsphere", str: 1})); assert.eq(0, coll.aggregate([geoNearStage]).itcount()); assert.eq(1, coll.aggregate([geoNearStage], {collation: {locale: "en_US", strength: 2}}).itcount()); @@ -1329,7 +1329,7 @@ assert.eq(1, coll.aggregate([geoNearStage], {collation: {locale: "en_US", streng // incompatible with string predicate. assert.commandWorked(coll.dropIndexes()); assert.commandWorked( - coll.ensureIndex({geo: "2dsphere", str: 1}, {collation: {locale: "en_US", strength: 3}})); + coll.createIndex({geo: "2dsphere", str: 1}, {collation: {locale: "en_US", strength: 3}})); assert.eq(0, coll.aggregate([geoNearStage]).itcount()); assert.eq(1, coll.aggregate([geoNearStage], {collation: {locale: "en_US", strength: 2}}).itcount()); @@ -1337,7 +1337,7 @@ assert.eq(1, coll.aggregate([geoNearStage], {collation: {locale: "en_US", streng // compatible with string predicate. assert.commandWorked(coll.dropIndexes()); assert.commandWorked( - coll.ensureIndex({geo: "2dsphere", str: 1}, {collation: {locale: "en_US", strength: 2}})); + coll.createIndex({geo: "2dsphere", str: 1}, {collation: {locale: "en_US", strength: 2}})); assert.eq(0, coll.aggregate([geoNearStage]).itcount()); assert.eq(1, coll.aggregate([geoNearStage], {collation: {locale: "en_US", strength: 2}}).itcount()); @@ -1346,7 +1346,7 @@ assert.eq(1, coll.aggregate([geoNearStage], {collation: {locale: "en_US", streng coll.drop(); assert.commandWorked( db.createCollection(coll.getName(), {collation: {locale: "en_US", strength: 2}})); -assert.commandWorked(coll.ensureIndex({geo: "2dsphere"})); +assert.commandWorked(coll.createIndex({geo: "2dsphere"})); assert.commandWorked(coll.insert({geo: {type: "Point", coordinates: [0, 0]}, str: "abc"})); assert.eq(1, coll.aggregate([geoNearStage]).itcount()); @@ -1355,7 +1355,7 @@ assert.eq(1, coll.aggregate([geoNearStage]).itcount()); coll.drop(); assert.commandWorked( db.createCollection(coll.getName(), {collation: {locale: "en_US", strength: 2}})); -assert.commandWorked(coll.ensureIndex({geo: "2dsphere"})); +assert.commandWorked(coll.createIndex({geo: "2dsphere"})); assert.commandWorked(coll.insert({geo: {type: "Point", coordinates: [0, 0]}, str: "abc"})); assert.eq(0, coll.aggregate([geoNearStage], {collation: {locale: "simple"}}).itcount()); @@ -1378,7 +1378,7 @@ if (db.getMongo().useReadCommands()) { // predicate not indexed. coll.drop(); assert.commandWorked(coll.insert({geo: {type: "Point", coordinates: [0, 0]}, str: "abc"})); - assert.commandWorked(coll.ensureIndex({geo: "2dsphere"})); + assert.commandWorked(coll.createIndex({geo: "2dsphere"})); assert.eq( 0, coll.find( @@ -1394,7 +1394,7 @@ if (db.getMongo().useReadCommands()) { // Find with $nearSphere should return correct results when no collation specified and // string predicate indexed. assert.commandWorked(coll.dropIndexes()); - assert.commandWorked(coll.ensureIndex({geo: "2dsphere", str: 1})); + assert.commandWorked(coll.createIndex({geo: "2dsphere", str: 1})); assert.eq( 0, coll.find( @@ -1411,7 +1411,7 @@ if (db.getMongo().useReadCommands()) { // collation on index is incompatible with string predicate. assert.commandWorked(coll.dropIndexes()); assert.commandWorked( - coll.ensureIndex({geo: "2dsphere", str: 1}, {collation: {locale: "en_US", strength: 3}})); + coll.createIndex({geo: "2dsphere", str: 1}, {collation: {locale: "en_US", strength: 3}})); assert.eq( 0, coll.find( @@ -1428,7 +1428,7 @@ if (db.getMongo().useReadCommands()) { // collation on index is compatible with string predicate. assert.commandWorked(coll.dropIndexes()); assert.commandWorked( - coll.ensureIndex({geo: "2dsphere", str: 1}, {collation: {locale: "en_US", strength: 2}})); + coll.createIndex({geo: "2dsphere", str: 1}, {collation: {locale: "en_US", strength: 2}})); assert.eq( 0, coll.find( @@ -1886,7 +1886,7 @@ if (db.getMongo().useReadCommands()) { // Ensure results from index with min/max query are sorted to match requested collation. coll.drop(); - assert.commandWorked(coll.ensureIndex({a: 1, b: 1})); + assert.commandWorked(coll.createIndex({a: 1, b: 1})); assert.commandWorked( coll.insert([{a: 1, b: 1}, {a: 1, b: 2}, {a: 1, b: "A"}, {a: 1, b: "a"}, {a: 2, b: 2}])); var expected = [{a: 1, b: 1}, {a: 1, b: 2}, {a: 1, b: "a"}, {a: 1, b: "A"}, {a: 2, b: 2}]; diff --git a/jstests/core/collmod.js b/jstests/core/collmod.js index c70a806c2d7..2f71b39c485 100644 --- a/jstests/core/collmod.js +++ b/jstests/core/collmod.js @@ -53,7 +53,7 @@ function findCollectionInfo() { assert.commandFailed(t.runCommand('collmod', {NotARealOption: 1})); // add a TTL index -t.ensureIndex({a: 1}, {"name": "index1", "expireAfterSeconds": 50}); +t.createIndex({a: 1}, {"name": "index1", "expireAfterSeconds": 50}); assert(findTTL({a: 1}, 50), "TTL index not added"); // try to modify it with a bad key pattern @@ -98,7 +98,7 @@ assert.commandFailed(db.runCommand({ // try to modify a faulty TTL index with a non-numeric expireAfterSeconds field t.dropIndex({a: 1}); -t.ensureIndex({a: 1}, {"expireAfterSeconds": "50"}); +t.createIndex({a: 1}, {"expireAfterSeconds": "50"}); var res = db.runCommand({"collMod": coll, "index": {"keyPattern": {a: 1}, "expireAfterSeconds": 100}}); debug(res); @@ -106,7 +106,7 @@ assert.eq(0, res.ok, "shouldn't be able to modify faulty index spec"); // try with new index, this time set expireAfterSeconds t.dropIndex({a: 1}); -t.ensureIndex({a: 1}, {"expireAfterSeconds": 50}); +t.createIndex({a: 1}, {"expireAfterSeconds": 50}); var res = db.runCommand({"collMod": coll, "index": {"keyPattern": {a: 1}, "expireAfterSeconds": 100}}); debug(res); diff --git a/jstests/core/compact_keeps_indexes.js b/jstests/core/compact_keeps_indexes.js index 4371513b3d9..f4f59165272 100644 --- a/jstests/core/compact_keeps_indexes.js +++ b/jstests/core/compact_keeps_indexes.js @@ -15,7 +15,7 @@ var coll = db.compact_keeps_indexes; coll.drop(); coll.insert({_id: 1, x: 1}); -coll.ensureIndex({x: 1}); +coll.createIndex({x: 1}); assert.eq(coll.getIndexes().length, 2); diff --git a/jstests/core/count.js b/jstests/core/count.js index 523b0743c3f..c34f8721cef 100644 --- a/jstests/core/count.js +++ b/jstests/core/count.js @@ -17,13 +17,13 @@ assert.eq(2, coll.count()); coll.drop(); assert.commandWorked(coll.insert({a: true, b: false})); -assert.commandWorked(coll.ensureIndex({b: 1, a: 1})); +assert.commandWorked(coll.createIndex({b: 1, a: 1})); assert.eq(1, coll.find({a: true, b: false}).count()); assert.eq(1, coll.find({b: false, a: true}).count()); coll.drop(); assert.commandWorked(coll.insert({a: true, b: false})); -assert.commandWorked(coll.ensureIndex({b: 1, a: 1, c: 1})); +assert.commandWorked(coll.createIndex({b: 1, a: 1, c: 1})); assert.eq(1, coll.find({a: true, b: false}).count()); assert.eq(1, coll.find({b: false, a: true}).count()); diff --git a/jstests/core/count4.js b/jstests/core/count4.js index ac0b3d3491f..2bb35190bd8 100644 --- a/jstests/core/count4.js +++ b/jstests/core/count4.js @@ -13,7 +13,7 @@ q = { assert.eq(50, t.find(q).count(), "A"); assert.eq(50, t.find(q).itcount(), "B"); -t.ensureIndex({x: 1}); +t.createIndex({x: 1}); assert.eq(50, t.find(q).count(), "C"); assert.eq(50, t.find(q).itcount(), "D"); diff --git a/jstests/core/count5.js b/jstests/core/count5.js index b89eb88d494..ceedf62b336 100644 --- a/jstests/core/count5.js +++ b/jstests/core/count5.js @@ -14,7 +14,7 @@ q = { assert.eq(50, t.find(q).count(), "A"); assert.eq(50, t.find(q).itcount(), "B"); -t.ensureIndex({x: 1}); +t.createIndex({x: 1}); assert.eq(50, t.find(q).count(), "C"); assert.eq(50, t.find(q).itcount(), "D"); diff --git a/jstests/core/count6.js b/jstests/core/count6.js index 46fb428ef97..78735c89c26 100644 --- a/jstests/core/count6.js +++ b/jstests/core/count6.js @@ -6,7 +6,7 @@ t = db.jstests_count6; function checkCountForObject(obj) { t.drop(); - t.ensureIndex({b: 1, a: 1}); + t.createIndex({b: 1, a: 1}); function checkCounts(query, expected) { assert.eq(expected, t.count(query), "A1"); diff --git a/jstests/core/count7.js b/jstests/core/count7.js index 95417e241de..443134474a8 100644 --- a/jstests/core/count7.js +++ b/jstests/core/count7.js @@ -5,7 +5,7 @@ t = db.jstests_count7; t.drop(); -t.ensureIndex({a: 1}); +t.createIndex({a: 1}); t.save({a: 'algebra'}); t.save({a: 'apple'}); t.save({a: 'azores'}); diff --git a/jstests/core/count9.js b/jstests/core/count9.js index 517322a9310..062f099e513 100644 --- a/jstests/core/count9.js +++ b/jstests/core/count9.js @@ -3,7 +3,7 @@ t = db.jstests_count9; t.drop(); -t.ensureIndex({a: 1}); +t.createIndex({a: 1}); t.save({a: ['a', 'b', 'a']}); assert.eq(1, t.count({a: 'a'})); @@ -12,7 +12,7 @@ t.save({a: ['a', 'b', 'a']}); assert.eq(2, t.count({a: 'a'})); t.drop(); -t.ensureIndex({a: 1, b: 1}); +t.createIndex({a: 1, b: 1}); t.save({a: ['a', 'b', 'a'], b: 'r'}); assert.eq(1, t.count({a: 'a', b: 'r'})); @@ -23,6 +23,6 @@ assert.eq(2, t.count({a: 'a', b: 'r'})); assert.eq(2, t.count({a: 'a'})); t.drop(); -t.ensureIndex({'a.b': 1, 'a.c': 1}); +t.createIndex({'a.b': 1, 'a.c': 1}); t.save({a: [{b: 'b', c: 'c'}, {b: 'b', c: 'c'}]}); assert.eq(1, t.count({'a.b': 'b', 'a.c': 'c'})); diff --git a/jstests/core/count_hint.js b/jstests/core/count_hint.js index 21c7a37b87d..5ba9514de87 100644 --- a/jstests/core/count_hint.js +++ b/jstests/core/count_hint.js @@ -18,7 +18,7 @@ assert.commandWorked(coll.insert({i: 2})); assert.eq(2, coll.find().count()); -assert.commandWorked(coll.ensureIndex({i: 1})); +assert.commandWorked(coll.createIndex({i: 1})); assert.eq(2, coll.find().hint("i_1").count()); assert.eq(2, coll.find().hint({i: 1}).count()); @@ -30,7 +30,7 @@ assert.eq(2, coll.find().hint("_id_").count()); assert.eq(2, coll.find().hint({_id: 1}).count()); // Create a sparse index which should have no entries. -assert.commandWorked(coll.ensureIndex({x: 1}, {sparse: true})); +assert.commandWorked(coll.createIndex({x: 1}, {sparse: true})); // A hint should be respected, even if it results in the wrong answer. assert.eq(0, coll.find().hint("x_1").count()); diff --git a/jstests/core/countb.js b/jstests/core/countb.js index bd6f9507fd2..869825b25a1 100644 --- a/jstests/core/countb.js +++ b/jstests/core/countb.js @@ -7,7 +7,7 @@ t = db.jstests_countb; t.drop(); -t.ensureIndex({a: 1}); +t.createIndex({a: 1}); t.save({a: ['a', 'b']}); assert.eq(0, t.find({a: {$in: ['a'], $gt: 'b'}}).count()); assert.eq(0, t.find({$and: [{a: 'a'}, {a: {$gt: 'b'}}]}).count()); diff --git a/jstests/core/countc.js b/jstests/core/countc.js index 876129c573f..5f0d31b769c 100644 --- a/jstests/core/countc.js +++ b/jstests/core/countc.js @@ -14,7 +14,7 @@ t.drop(); // Match a subset of inserted values within a $in operator. t.drop(); -t.ensureIndex({a: 1}); +t.createIndex({a: 1}); // Save 'a' values 0, 0.5, 1.5, 2.5 ... 97.5, 98.5, 99. t.save({a: 0}); t.save({a: 99}); @@ -31,7 +31,7 @@ assert.eq(2, t.count({a: {$in: vals}})); // Match 'a' values within upper and lower limits. t.drop(); -t.ensureIndex({a: 1}); +t.createIndex({a: 1}); t.save({a: [1, 2]}); // Will match because 'a' is in range. t.save({a: 9}); // Will not match because 'a' is not in range. // Only one document matches. @@ -39,14 +39,14 @@ assert.eq(1, t.count({a: {$gt: 0, $lt: 5}})); // Match two nested fields within an array. t.drop(); -t.ensureIndex({'a.b': 1, 'a.c': 1}); +t.createIndex({'a.b': 1, 'a.c': 1}); t.save({a: [{b: 2, c: 3}, {}]}); // The document does not match because its c value is 3. assert.eq(0, t.count({'a.b': 2, 'a.c': 2})); // $gt:string only matches strings. t.drop(); -t.ensureIndex({a: 1}); +t.createIndex({a: 1}); t.save({a: 'a'}); // Will match. t.save({a: {}}); // Will not match because {} is not a string. // Only one document matches. @@ -54,7 +54,7 @@ assert.eq(1, t.count({a: {$gte: ''}})); // $lte:date only matches dates. t.drop(); -t.ensureIndex({a: 1}); +t.createIndex({a: 1}); t.save({a: new Date(1)}); // Will match. t.save({a: true}); // Will not match because 'true' is not a date. // Only one document matches. @@ -62,14 +62,14 @@ assert.eq(1, t.count({a: {$lte: new Date(1)}})); // Querying for 'undefined' triggers an error. t.drop(); -t.ensureIndex({a: 1}); +t.createIndex({a: 1}); assert.throws(function() { t.count({a: undefined}); }); // Count using a descending order index. t.drop(); -t.ensureIndex({a: -1}); +t.createIndex({a: -1}); t.save({a: 1}); t.save({a: 2}); t.save({a: 3}); @@ -80,7 +80,7 @@ assert.eq(2, t.count({a: {$lt: 3}})); // Count using a compound index. t.drop(); -t.ensureIndex({a: 1, b: 1}); +t.createIndex({a: 1, b: 1}); t.save({a: 1, b: 2}); t.save({a: 2, b: 1}); t.save({a: 2, b: 3}); @@ -95,7 +95,7 @@ assert.eq(1, t.count({a: 1, b: {$lt: 3}})); // Count using a compound descending order index. t.drop(); -t.ensureIndex({a: 1, b: -1}); +t.createIndex({a: 1, b: -1}); t.save({a: 1, b: 2}); t.save({a: 2, b: 1}); t.save({a: 2, b: 3}); @@ -108,13 +108,13 @@ assert.eq(1, t.count({a: 1, b: {$lt: 3}})); // Count with a multikey value. t.drop(); -t.ensureIndex({a: 1}); +t.createIndex({a: 1}); t.save({a: [1, 2]}); assert.eq(1, t.count({a: {$gt: 0, $lte: 2}})); // Count with a match constraint on an unindexed field. t.drop(); -t.ensureIndex({a: 1}); +t.createIndex({a: 1}); t.save({a: 1, b: 1}); t.save({a: 1, b: 2}); assert.eq(1, t.count({a: 1, $where: 'this.b == 1'})); diff --git a/jstests/core/coveredIndex2.js b/jstests/core/coveredIndex2.js index 9ec3ce529ae..41092e7d525 100644 --- a/jstests/core/coveredIndex2.js +++ b/jstests/core/coveredIndex2.js @@ -19,7 +19,7 @@ assert.eq(t.findOne({a: 1}).a, 1, "Cannot find right record"); assert.eq(t.count(), 2, "Not right length"); // use simple index -t.ensureIndex({a: 1}); +t.createIndex({a: 1}); var plan = t.find({a: 1}).explain(); assert(!isIndexOnly(db, plan.queryPlanner.winningPlan), "Find using covered index but all fields are returned"); diff --git a/jstests/core/coveredIndex3.js b/jstests/core/coveredIndex3.js index a054840b6df..8b15b40e862 100644 --- a/jstests/core/coveredIndex3.js +++ b/jstests/core/coveredIndex3.js @@ -30,7 +30,7 @@ if (0) { // SERVER-4975 for (i = 0; i < 30; ++i) { t.drop(); - t.ensureIndex({a: 1}); + t.createIndex({a: 1}); for (j = 0; j < 1000; ++j) { t.save({a: j}); diff --git a/jstests/core/coveredIndex4.js b/jstests/core/coveredIndex4.js index 125cf22da3a..e62162d1685 100644 --- a/jstests/core/coveredIndex4.js +++ b/jstests/core/coveredIndex4.js @@ -9,8 +9,8 @@ t = db.jstests_coveredIndex4; t.drop(); -t.ensureIndex({a: 1}); -t.ensureIndex({b: 1}); +t.createIndex({a: 1}); +t.createIndex({b: 1}); orClause = []; for (i = 0; i < 200; ++i) { diff --git a/jstests/core/covered_index_compound_1.js b/jstests/core/covered_index_compound_1.js index 2f2d45adabd..a43a4f70ec5 100644 --- a/jstests/core/covered_index_compound_1.js +++ b/jstests/core/covered_index_compound_1.js @@ -16,7 +16,7 @@ coll.drop(); for (i = 0; i < 100; i++) { coll.insert({a: i, b: "strvar_" + (i % 13), c: NumberInt(i % 10)}); } -coll.ensureIndex({a: 1, b: -1, c: 1}); +coll.createIndex({a: 1, b: -1, c: 1}); // Test equality - all indexed fields queried and projected var plan = coll.find({a: 10, b: "strvar_10", c: 0}, {a: 1, b: 1, c: 1, _id: 0}) diff --git a/jstests/core/covered_index_negative_1.js b/jstests/core/covered_index_negative_1.js index 4028b1159b2..06d4119ffe4 100644 --- a/jstests/core/covered_index_negative_1.js +++ b/jstests/core/covered_index_negative_1.js @@ -16,10 +16,10 @@ for (i = 0; i < 100; i++) { coll.insert( {a: i, b: "strvar_" + (i % 13), c: NumberInt(i % 10), d: i * 10, e: [i, i % 10], f: i}); } -coll.ensureIndex({a: 1, b: -1, c: 1}); -coll.ensureIndex({e: 1}); -coll.ensureIndex({d: 1}); -coll.ensureIndex({f: "hashed"}); +coll.createIndex({a: 1, b: -1, c: 1}); +coll.createIndex({e: 1}); +coll.createIndex({d: 1}); +coll.createIndex({f: "hashed"}); // Test no projection var plan = diff --git a/jstests/core/covered_index_simple_1.js b/jstests/core/covered_index_simple_1.js index c49e5a2bc8e..ce8f1978a89 100644 --- a/jstests/core/covered_index_simple_1.js +++ b/jstests/core/covered_index_simple_1.js @@ -25,7 +25,7 @@ for (i = 0; i < 5; i++) { coll.insert({foo: "string"}); coll.insert({foo: {bar: 1}}); coll.insert({foo: null}); -coll.ensureIndex({foo: 1}); +coll.createIndex({foo: 1}); // Test equality with int value var plan = coll.find({foo: 1}, {foo: 1, _id: 0}).hint({foo: 1}).explain("executionStats"); diff --git a/jstests/core/covered_index_simple_2.js b/jstests/core/covered_index_simple_2.js index 67548ed8c06..066bf1bae4c 100644 --- a/jstests/core/covered_index_simple_2.js +++ b/jstests/core/covered_index_simple_2.js @@ -19,7 +19,7 @@ for (i = 0; i < 10; i++) { coll.insert({foo: "string"}); coll.insert({foo: {bar: 1}}); coll.insert({foo: null}); -coll.ensureIndex({foo: 1}, {unique: true}); +coll.createIndex({foo: 1}, {unique: true}); // Test equality with int value var plan = coll.find({foo: 1}, {foo: 1, _id: 0}).hint({foo: 1}).explain("executionStats"); diff --git a/jstests/core/covered_index_simple_3.js b/jstests/core/covered_index_simple_3.js index 5e654475252..c0e62a9243d 100644 --- a/jstests/core/covered_index_simple_3.js +++ b/jstests/core/covered_index_simple_3.js @@ -22,7 +22,7 @@ for (i = 0; i < 5; i++) { coll.insert({foo: "string"}); coll.insert({foo: {bar: 1}}); coll.insert({foo: null}); -coll.ensureIndex({foo: 1}, {sparse: true, unique: true}); +coll.createIndex({foo: 1}, {sparse: true, unique: true}); // Test equality with int value var plan = coll.find({foo: 1}, {foo: 1, _id: 0}).hint({foo: 1}).explain("executionStats"); @@ -85,7 +85,7 @@ assert.eq(0, // Check that $nin can be covered. coll.dropIndexes(); -coll.ensureIndex({bar: 1}); +coll.createIndex({bar: 1}); var plan = coll.find({bar: {$nin: [5, 8]}}, {bar: 1, _id: 0}).hint({bar: 1}).explain("executionStats"); assert(isIndexOnly(db, plan.queryPlanner.winningPlan), diff --git a/jstests/core/covered_index_sort_1.js b/jstests/core/covered_index_sort_1.js index 4b8cea2e825..526ddfbaa42 100644 --- a/jstests/core/covered_index_sort_1.js +++ b/jstests/core/covered_index_sort_1.js @@ -25,7 +25,7 @@ for (i = 0; i < 5; i++) { coll.insert({foo: "1"}); coll.insert({foo: {bar: 1}}); coll.insert({foo: null}); -coll.ensureIndex({foo: 1}); +coll.createIndex({foo: 1}); // Test no query and sort ascending var plan = coll.find({}, {foo: 1, _id: 0}).sort({foo: 1}).hint({foo: 1}).explain("executionStats"); diff --git a/jstests/core/covered_index_sort_3.js b/jstests/core/covered_index_sort_3.js index 1107e0584dc..0e9b1ea30ff 100644 --- a/jstests/core/covered_index_sort_3.js +++ b/jstests/core/covered_index_sort_3.js @@ -17,7 +17,7 @@ for (i = 0; i < 100; i++) { coll.insert({a: i, b: "strvar_" + (i % 13), c: NumberInt(i % 10)}); } -coll.ensureIndex({a: 1, b: -1, c: 1}); +coll.createIndex({a: 1, b: -1, c: 1}); // Test no query, sort on all fields in index order var plan = coll.find({}, {b: 1, c: 1, _id: 0}) diff --git a/jstests/core/create_index_helper_validation.js b/jstests/core/create_index_helper_validation.js index 805c567316d..1b11a50c6ca 100644 --- a/jstests/core/create_index_helper_validation.js +++ b/jstests/core/create_index_helper_validation.js @@ -20,7 +20,7 @@ assert.throws(() => coll.createIndex( {background: true}, {unique: true})); -assert.throws(() => coll.ensureIndex( +assert.throws(() => coll.createIndex( /* keys */ {a: 1}, /* options */ {}, /* commitQuorum */ "majority", diff --git a/jstests/core/crud_api.js b/jstests/core/crud_api.js index 4b37300e9b1..9eb09ab6436 100644 --- a/jstests/core/crud_api.js +++ b/jstests/core/crud_api.js @@ -700,7 +700,7 @@ var crudAPISpecTests = function crudAPISpecTests() { // Drop collection coll.drop(); - coll.ensureIndex({a: 1}, {unique: true}); + coll.createIndex({a: 1}, {unique: true}); // Should throw duplicate key error assert.throws(function() { diff --git a/jstests/core/cursor3.js b/jstests/core/cursor3.js index 1a7e0dfcc7e..f416ec47931 100644 --- a/jstests/core/cursor3.js +++ b/jstests/core/cursor3.js @@ -23,7 +23,7 @@ t.save({a: 0}); t.save({a: 1}); t.save({a: 2}); -t.ensureIndex({a: 1}); +t.createIndex({a: 1}); checkResults([1], t.find({a: 1}).sort({a: 1}).hint({a: 1}), testNum++); checkResults([1], t.find({a: 1}).sort({a: -1}).hint({a: 1}), testNum++); diff --git a/jstests/core/cursor4.js b/jstests/core/cursor4.js index dd7875d0836..d0440d329f1 100644 --- a/jstests/core/cursor4.js +++ b/jstests/core/cursor4.js @@ -15,7 +15,7 @@ function testConstrainedFindMultiFieldSorting(db) { entries = [{a: 0, b: 0}, {a: 0, b: 1}, {a: 1, b: 1}, {a: 1, b: 1}, {a: 2, b: 0}]; for (i = 0; i < entries.length; ++i) r.save(entries[i]); - r.ensureIndex({a: 1, b: 1}); + r.createIndex({a: 1, b: 1}); reverseEntries = entries.slice(); reverseEntries.reverse(); diff --git a/jstests/core/cursor5.js b/jstests/core/cursor5.js index 0232b92e4cc..aab03473255 100644 --- a/jstests/core/cursor5.js +++ b/jstests/core/cursor5.js @@ -26,7 +26,7 @@ function testBoundsWithSubobjectIndexes(db) { r.save(z[i]); idx = {"a.d": 1, a: 1, e: -1}; rIdx = {"a.d": -1, a: -1, e: 1}; - r.ensureIndex(idx); + r.createIndex(idx); checkResults([z[0], z[4], z[2]], r.find({e: 4}).sort(idx).hint(idx)); checkResults([z[1], z[3]], r.find({e: {$gt: 4}, "a.b": 1}).sort(idx).hint(idx)); diff --git a/jstests/core/cursor6.js b/jstests/core/cursor6.js index d2c56c00e75..7c8daa1bfcb 100644 --- a/jstests/core/cursor6.js +++ b/jstests/core/cursor6.js @@ -60,7 +60,7 @@ z = [{a: 1, b: 1}, {a: 1, b: 2}, {a: 2, b: 1}, {a: 2, b: 2}]; for (i = 0; i < z.length; ++i) r.save(z[i]); -r.ensureIndex({a: 1, b: -1}); +r.createIndex({a: 1, b: -1}); check(false); check(true); diff --git a/jstests/core/cursor7.js b/jstests/core/cursor7.js index 7807dbe22f5..4a21c420274 100644 --- a/jstests/core/cursor7.js +++ b/jstests/core/cursor7.js @@ -17,7 +17,7 @@ function testMultipleInequalities(db) { r.save(z[i]); idx = {a: 1, b: 1}; rIdx = {a: -1, b: -1}; - r.ensureIndex(idx); + r.createIndex(idx); checkResults([z[2], z[3]], r.find({a: {$gt: 3}}).sort(idx).hint(idx)); checkResults([z[2]], r.find({a: {$gt: 3, $lt: 7}}).sort(idx).hint(idx)); diff --git a/jstests/core/date2.js b/jstests/core/date2.js index 15993815b14..a398058d771 100644 --- a/jstests/core/date2.js +++ b/jstests/core/date2.js @@ -3,7 +3,7 @@ t = db.jstests_date2; t.drop(); -t.ensureIndex({a: 1}); +t.createIndex({a: 1}); var obj = {a: new Timestamp(0, 1)}; // in old versions this was == to new Date(1) t.save(obj); diff --git a/jstests/core/date3.js b/jstests/core/date3.js index 80279a9559c..e3eaea620ec 100644 --- a/jstests/core/date3.js +++ b/jstests/core/date3.js @@ -29,5 +29,5 @@ function test() { } test(); -t.ensureIndex({d: 1}); +t.createIndex({d: 1}); test(); diff --git a/jstests/core/distinct3.js b/jstests/core/distinct3.js index 654cd8e352a..6a67635500d 100644 --- a/jstests/core/distinct3.js +++ b/jstests/core/distinct3.js @@ -10,8 +10,8 @@ t = db.jstests_distinct3; t.drop(); -t.ensureIndex({a: 1}); -t.ensureIndex({b: 1}); +t.createIndex({a: 1}); +t.createIndex({b: 1}); var bulk = t.initializeUnorderedBulkOp(); for (i = 0; i < 50; ++i) { diff --git a/jstests/core/distinct_array1.js b/jstests/core/distinct_array1.js index 2d3a96a6af6..cb82c25bbff 100644 --- a/jstests/core/distinct_array1.js +++ b/jstests/core/distinct_array1.js @@ -19,7 +19,7 @@ res = t.distinct("a.1").sort(); assert.eq("2,3,4", res.toString()); // With index. -t.ensureIndex({a: 1}); +t.createIndex({a: 1}); res = t.distinct("a").sort(); assert.eq("1,2,3,4,5,9", res.toString()); @@ -51,7 +51,7 @@ res = t.distinct("a.1.b").sort(); assert.eq("d,e,f", res.toString()); // With index. -t.ensureIndex({"a.b": 1}); +t.createIndex({"a.b": 1}); res = t.distinct("a.b"); res.sort(); // TODO SERVER-14832 The presence of an index may change results, but only if the index is not @@ -85,7 +85,7 @@ res = t.distinct("_id.a.1").sort(); assert.eq("2,3,4", res.toString()); // With index. -t.ensureIndex({"_id.a": 1}); +t.createIndex({"_id.a": 1}); res = t.distinct("_id.a").sort(); // TODO SERVER-14832: distinct() may incorrectly return null in presence of index. assert.eq([1, 2, 3, 4, 5, 9, null], res); diff --git a/jstests/core/distinct_index2.js b/jstests/core/distinct_index2.js index d1b72565102..1f552102059 100644 --- a/jstests/core/distinct_index2.js +++ b/jstests/core/distinct_index2.js @@ -1,8 +1,8 @@ t = db.distinct_index2; t.drop(); -t.ensureIndex({a: 1, b: 1}); -t.ensureIndex({c: 1}); +t.createIndex({a: 1, b: 1}); +t.createIndex({c: 1}); // Uniformly distributed dataset. // If we use a randomly generated dataset, we might not @@ -37,5 +37,5 @@ check("c"); // hashed index should produce same results. t.dropIndexes(); -t.ensureIndex({a: "hashed"}); +t.createIndex({a: "hashed"}); check("a"); diff --git a/jstests/core/drop.js b/jstests/core/drop.js index ea395660a5f..769a8cd348c 100644 --- a/jstests/core/drop.js +++ b/jstests/core/drop.js @@ -12,12 +12,12 @@ assert(!res.ok, tojson(res)); assert.eq(0, coll.getIndexes().length, "A"); coll.save({}); assert.eq(1, coll.getIndexes().length, "B"); -coll.ensureIndex({a: 1}); +coll.createIndex({a: 1}); assert.eq(2, coll.getIndexes().length, "C"); assert.commandWorked(db.runCommand({drop: coll.getName()})); assert.eq(0, coll.getIndexes().length, "D"); -coll.ensureIndex({a: 1}); +coll.createIndex({a: 1}); assert.eq(2, coll.getIndexes().length, "E"); assert.commandWorked(db.runCommand({dropIndexes: coll.getName(), index: "*"}), "drop indexes A"); assert.eq(1, coll.getIndexes().length, "G"); diff --git a/jstests/core/drop_index.js b/jstests/core/drop_index.js index 60dbec0e3ea..e808b1f7829 100644 --- a/jstests/core/drop_index.js +++ b/jstests/core/drop_index.js @@ -57,7 +57,7 @@ assert.commandFailedWithCode(t.dropIndex({_id: 1}), ErrorCodes.InvalidOptions); // Ensure you can recreate indexes, even if you don't use dropIndex method. // Prior to SERVER-7168, the shell used to cache names of indexes created using -// Collection.ensureIndex(). +// Collection.createIndex(). assert.commandWorked(t.createIndex({a: 1})); assertIndexes(['a_1', 'c_1', 'd_1', 'e_1'], 'recreating {a: 1}'); diff --git a/jstests/core/dropdb_race.js b/jstests/core/dropdb_race.js index 6bcd334e7ab..8f1356db1d6 100644 --- a/jstests/core/dropdb_race.js +++ b/jstests/core/dropdb_race.js @@ -25,7 +25,7 @@ for (var pass = 0; pass < 100; pass++) { } t.insert({x: 1}); t.insert({x: 3}); - t.ensureIndex({x: 1}); + t.createIndex({x: 1}); sleep(s); if (pass % 13 == 0) t.drop(); diff --git a/jstests/core/exists.js b/jstests/core/exists.js index e0ba49fabd8..b85d80c36a7 100644 --- a/jstests/core/exists.js +++ b/jstests/core/exists.js @@ -36,10 +36,10 @@ function dotest(n) { } dotest("before index"); -t.ensureIndex({"a": 1}); -t.ensureIndex({"a.b": 1}); -t.ensureIndex({"a.b.c": 1}); -t.ensureIndex({"a.b.c.d": 1}); +t.createIndex({"a": 1}); +t.createIndex({"a.b": 1}); +t.createIndex({"a.b.c": 1}); +t.createIndex({"a.b.c.d": 1}); dotest("after index"); assert.eq(1, t.find({a: {$exists: false}}).hint({a: 1}).itcount()); diff --git a/jstests/core/exists2.js b/jstests/core/exists2.js index 3b4580cd310..0764d859c3b 100644 --- a/jstests/core/exists2.js +++ b/jstests/core/exists2.js @@ -9,6 +9,6 @@ assert.eq(2, t.find({a: 1, b: 1}).itcount(), "A2"); assert.eq(1, t.find({a: 1, b: 1, c: {"$exists": true}}).itcount(), "A3"); assert.eq(1, t.find({a: 1, b: 1, c: {"$exists": false}}).itcount(), "A4"); -t.ensureIndex({a: 1, b: 1, c: 1}); +t.createIndex({a: 1, b: 1, c: 1}); assert.eq(1, t.find({a: 1, b: 1, c: {"$exists": true}}).itcount(), "B1"); assert.eq(1, t.find({a: 1, b: 1, c: {"$exists": false}}).itcount(), "B2"); diff --git a/jstests/core/exists3.js b/jstests/core/exists3.js index e4ce03437bb..510d63c3752 100644 --- a/jstests/core/exists3.js +++ b/jstests/core/exists3.js @@ -11,7 +11,7 @@ assert.eq(1, t.find({c: {$exists: false}}).itcount()); assert.eq(1, t.find({c: {$exists: false}}).sort({c: -1}).itcount()); // now we have an index on the sort key -t.ensureIndex({c: -1}); +t.createIndex({c: -1}); assert.eq(1, t.find({c: {$exists: false}}).sort({c: -1}).itcount()); assert.eq(1, t.find({c: {$exists: false}}).itcount()); diff --git a/jstests/core/exists4.js b/jstests/core/exists4.js index 2979a60f276..a533ca53e9c 100644 --- a/jstests/core/exists4.js +++ b/jstests/core/exists4.js @@ -3,7 +3,7 @@ t = db.jstests_exists4; t.drop(); -t.ensureIndex({date: -1, country_code: 1, user_id: 1}, {unique: 1, background: 1}); +t.createIndex({date: -1, country_code: 1, user_id: 1}, {unique: 1, background: 1}); t.insert({date: new Date("08/27/2010"), tot_visit: 100}); t.insert({date: new Date("08/27/2010"), country_code: "IT", tot_visit: 77}); t.insert({date: new Date("08/27/2010"), country_code: "ES", tot_visit: 23}); diff --git a/jstests/core/exists6.js b/jstests/core/exists6.js index 67ab7e5345d..736574db895 100644 --- a/jstests/core/exists6.js +++ b/jstests/core/exists6.js @@ -3,7 +3,7 @@ t = db.jstests_exists6; t.drop(); -t.ensureIndex({b: 1}); +t.createIndex({b: 1}); t.save({}); t.save({b: 1}); t.save({b: null}); @@ -14,7 +14,7 @@ assert.eq(1, t.find({b: {$exists: false}}).itcount()); assert.eq(1, t.find({b: {$not: {$exists: true}}}).itcount()); // Now check existence of second compound field. -t.ensureIndex({a: 1, b: 1}); +t.createIndex({a: 1, b: 1}); t.save({a: 1}); t.save({a: 1, b: 1}); t.save({a: 1, b: null}); diff --git a/jstests/core/exists7.js b/jstests/core/exists7.js index 74ea4e9719c..6ca55a42286 100644 --- a/jstests/core/exists7.js +++ b/jstests/core/exists7.js @@ -18,5 +18,5 @@ function testIntegerExistsSpec() { } testIntegerExistsSpec(); -t.ensureIndex({b: 1}); +t.createIndex({b: 1}); testIntegerExistsSpec(); diff --git a/jstests/core/exists9.js b/jstests/core/exists9.js index 444bcf731a1..3b245cd4188 100644 --- a/jstests/core/exists9.js +++ b/jstests/core/exists9.js @@ -12,7 +12,7 @@ assert.eq(1, t.count({'a.b': {$exists: false}})); assert.eq(0, t.count({'a.b': {$exists: true}})); // With index. -t.ensureIndex({'a.b': 1}); +t.createIndex({'a.b': 1}); assert.eq(1, t.find({'a.b': {$exists: false}}).hint({'a.b': 1}).itcount()); assert.eq(0, t.find({'a.b': {$exists: true}}).hint({'a.b': 1}).itcount()); @@ -25,7 +25,7 @@ assert.eq(1, t.count({a: {$exists: true}})); assert.eq(1, t.count({a: {$exists: false}})); // With index. -t.ensureIndex({a: 1}); +t.createIndex({a: 1}); assert.eq(1, t.find({a: {$exists: true}}).hint({a: 1}).itcount()); assert.eq(1, t.find({a: {$exists: false}}).hint({a: 1}).itcount()); @@ -38,6 +38,6 @@ assert.eq(1, t.count({'a.0': {$exists: true}})); assert.eq(1, t.count({'a.0': {$exists: false}})); // With index. -t.ensureIndex({'a.0': 1}); +t.createIndex({'a.0': 1}); assert.eq(1, t.find({'a.0': {$exists: true}}).hint({'a.0': 1}).itcount()); assert.eq(1, t.find({'a.0': {$exists: false}}).hint({'a.0': 1}).itcount()); diff --git a/jstests/core/existsa.js b/jstests/core/existsa.js index d1079310d71..2b5f70dd77f 100644 --- a/jstests/core/existsa.js +++ b/jstests/core/existsa.js @@ -19,7 +19,7 @@ function setIndex(_indexKeyField) { indexKeyField = _indexKeyField; indexKeySpec = {}; indexKeySpec[indexKeyField] = 1; - coll.ensureIndex(indexKeySpec, {sparse: true}); + coll.createIndex(indexKeySpec, {sparse: true}); } setIndex('a'); @@ -106,6 +106,6 @@ assertExistsUnindexed({'a.b': {$elemMatch: {$gt: 0, $not: {$exists: false}}}}, 1 // A non sparse index will not be disallowed. coll.drop(); assert.commandWorked(coll.insert({})); -coll.ensureIndex({a: 1}); +coll.createIndex({a: 1}); assert.eq(1, coll.find({a: {$exists: false}}).itcount()); })(); diff --git a/jstests/core/existsb.js b/jstests/core/existsb.js index d46266cdd16..64ee3cf9a88 100644 --- a/jstests/core/existsb.js +++ b/jstests/core/existsb.js @@ -57,20 +57,20 @@ function checkExistsNull() { checkExistsNull(); // try with a standard index -t.ensureIndex({a: 1}); +t.createIndex({a: 1}); checkExistsNull(); // try with a sparse index t.dropIndexes(); -t.ensureIndex({a: 1}, {sparse: true}); +t.createIndex({a: 1}, {sparse: true}); checkExistsNull(); // try with a compound index t.dropIndexes(); -t.ensureIndex({a: 1, b: 1}); +t.createIndex({a: 1, b: 1}); checkExistsNull(); // try with sparse compound index t.dropIndexes(); -t.ensureIndex({a: 1, b: 1}, {sparse: true}); +t.createIndex({a: 1, b: 1}, {sparse: true}); checkExistsNull(); diff --git a/jstests/core/explain1.js b/jstests/core/explain1.js index 09891f214dd..8450335159d 100644 --- a/jstests/core/explain1.js +++ b/jstests/core/explain1.js @@ -19,7 +19,7 @@ assert.eq(49, t.find(q).count(), "A"); assert.eq(49, t.find(q).itcount(), "B"); assert.eq(20, t.find(q).limit(20).itcount(), "C"); -t.ensureIndex({x: 1}); +t.createIndex({x: 1}); assert.eq(49, t.find(q).count(), "D"); assert.eq(49, t.find(q).itcount(), "E"); diff --git a/jstests/core/explain4.js b/jstests/core/explain4.js index 06c7bf0b359..df0d98382e0 100644 --- a/jstests/core/explain4.js +++ b/jstests/core/explain4.js @@ -6,7 +6,7 @@ t = db.jstests_explain4; t.drop(); -t.ensureIndex({a: 1}); +t.createIndex({a: 1}); for (i = 0; i < 10; ++i) { t.save({a: i, b: 0}); diff --git a/jstests/core/explain5.js b/jstests/core/explain5.js index 5bae866e096..50648cd8817 100644 --- a/jstests/core/explain5.js +++ b/jstests/core/explain5.js @@ -7,8 +7,8 @@ t = db.jstests_explain5; t.drop(); -t.ensureIndex({a: 1}); -t.ensureIndex({b: 1}); +t.createIndex({a: 1}); +t.createIndex({b: 1}); for (i = 0; i < 1000; ++i) { t.save({a: i, b: i % 3}); diff --git a/jstests/core/explain6.js b/jstests/core/explain6.js index dbbb767531c..f36640ce567 100644 --- a/jstests/core/explain6.js +++ b/jstests/core/explain6.js @@ -10,8 +10,8 @@ t = db.jstests_explain6; t.drop(); -t.ensureIndex({a: 1, b: 1}); -t.ensureIndex({b: 1, a: 1}); +t.createIndex({a: 1, b: 1}); +t.createIndex({b: 1, a: 1}); t.save({a: 0, b: 1}); t.save({a: 1, b: 0}); diff --git a/jstests/core/explain_count.js b/jstests/core/explain_count.js index 883f8b84ac7..8dc0854ab15 100644 --- a/jstests/core/explain_count.js +++ b/jstests/core/explain_count.js @@ -99,7 +99,7 @@ assertExplainCount({explainResults: explain, expectedCount: 0}); // Now add a bit of data to the collection. // On sharded clusters, we'll want the shard key to be indexed, so we make _id part of the index. // This means counts will not have to fetch from the document in order to get the shard key. -t.ensureIndex({a: 1, _id: 1}); +t.createIndex({a: 1, _id: 1}); for (var i = 0; i < 10; i++) { t.insert({_id: i, a: 1}); } diff --git a/jstests/core/explain_delete.js b/jstests/core/explain_delete.js index 1863979faa5..44a67ea21ca 100644 --- a/jstests/core/explain_delete.js +++ b/jstests/core/explain_delete.js @@ -43,7 +43,7 @@ explain = db.runCommand({explain: {delete: collName, deletes: [{q: {a: 1}, limit checkNWouldDelete(explain, 0); // Add an index but no data, and check that the explain still works. -t.ensureIndex({a: 1}); +t.createIndex({a: 1}); explain = db.runCommand({explain: {delete: collName, deletes: [{q: {a: 1}, limit: 0}]}}); checkNWouldDelete(explain, 0); diff --git a/jstests/core/explain_execution_error.js b/jstests/core/explain_execution_error.js index d2240452573..4515a050edc 100644 --- a/jstests/core/explain_execution_error.js +++ b/jstests/core/explain_execution_error.js @@ -117,8 +117,8 @@ assertExecError(result); // Now we introduce two indices. One provides the requested sort order, and // the other does not. -t.ensureIndex({b: 1}); -t.ensureIndex({c: 1}); +t.createIndex({b: 1}); +t.createIndex({c: 1}); // The query should no longer fail with a memory limit error because the planner can obtain // the sort by scanning an index. diff --git a/jstests/core/explain_find.js b/jstests/core/explain_find.js index fcf2e35053c..c42d59d7671 100644 --- a/jstests/core/explain_find.js +++ b/jstests/core/explain_find.js @@ -10,7 +10,7 @@ var collName = "jstests_explain_find"; var t = db[collName]; t.drop(); -t.ensureIndex({a: 1}); +t.createIndex({a: 1}); for (var i = 0; i < 10; i++) { t.insert({_id: i, a: i}); diff --git a/jstests/core/explain_large_bounds.js b/jstests/core/explain_large_bounds.js index 1ff7307e7d9..1ca27f9a8ef 100644 --- a/jstests/core/explain_large_bounds.js +++ b/jstests/core/explain_large_bounds.js @@ -8,7 +8,7 @@ const coll = db.jstests_explain_large_bounds; coll.drop(); -coll.ensureIndex({a: 1}); +coll.createIndex({a: 1}); let inClause = []; for (let i = 0; i < 1000000; i++) { diff --git a/jstests/core/explain_multi_plan.js b/jstests/core/explain_multi_plan.js index dc8f153e6cb..845438af91e 100644 --- a/jstests/core/explain_multi_plan.js +++ b/jstests/core/explain_multi_plan.js @@ -16,8 +16,8 @@ var coll = db.explainMultiPlan; coll.drop(); // Create indices to ensure there are multiple plans available. -assert.commandWorked(coll.ensureIndex({a: 1, b: 1})); -assert.commandWorked(coll.ensureIndex({a: 1, b: -1})); +assert.commandWorked(coll.createIndex({a: 1, b: 1})); +assert.commandWorked(coll.createIndex({a: 1, b: -1})); // Insert some data to work with. var bulk = coll.initializeOrderedBulkOp(); diff --git a/jstests/core/explain_shell_helpers.js b/jstests/core/explain_shell_helpers.js index 1a66a032143..cad5fec9141 100644 --- a/jstests/core/explain_shell_helpers.js +++ b/jstests/core/explain_shell_helpers.js @@ -22,7 +22,7 @@ load("jstests/libs/analyze_plan.js"); var explain; var stage; -t.ensureIndex({a: 1}); +t.createIndex({a: 1}); for (var i = 0; i < 10; i++) { t.insert({_id: i, a: i, b: 1}); } @@ -267,7 +267,7 @@ assert(planHasStage(db, explain.queryPlanner.winningPlan, "COUNT")); assert(planHasStage(db, explain.queryPlanner.winningPlan, "COUNT_SCAN")); // Explainable count with hint. -assert.commandWorked(t.ensureIndex({c: 1}, {sparse: true})); +assert.commandWorked(t.createIndex({c: 1}, {sparse: true})); explain = t.explain().count({c: {$exists: false}}, {hint: "c_1"}); assert.commandWorked(explain); assert(planHasStage(db, explain.queryPlanner.winningPlan, "IXSCAN")); diff --git a/jstests/core/expr.js b/jstests/core/expr.js index 1a23ac00d8b..a6861a4d2cf 100644 --- a/jstests/core/expr.js +++ b/jstests/core/expr.js @@ -190,7 +190,7 @@ if (db.getMongo().writeMode() === "commands") { coll.drop(); assert.commandWorked(coll.insert({geo: {type: "Point", coordinates: [0, 0]}, a: 0})); -assert.commandWorked(coll.ensureIndex({geo: "2dsphere"})); +assert.commandWorked(coll.createIndex({geo: "2dsphere"})); assert.eq(1, coll.aggregate({ $geoNear: { diff --git a/jstests/core/filemd5.js b/jstests/core/filemd5.js index b33611c1e90..064bf323bcf 100644 --- a/jstests/core/filemd5.js +++ b/jstests/core/filemd5.js @@ -17,7 +17,7 @@ assert.commandWorked(db.fs.chunks.insert({files_id: 1, n: 0, data: new BinData(0 assert.commandFailedWithCode(db.runCommand({filemd5: 1, root: "fs"}), ErrorCodes.NoQueryExecutionPlans); -db.fs.chunks.ensureIndex({files_id: 1, n: 1}); +db.fs.chunks.createIndex({files_id: 1, n: 1}); assert.commandWorked(db.runCommand({filemd5: 1, root: "fs"})); assert.commandFailedWithCode(db.runCommand({filemd5: 1, root: "fs", partialOk: 1, md5state: 5}), diff --git a/jstests/core/find6.js b/jstests/core/find6.js index 7edf1739c78..4c7a0a9384b 100644 --- a/jstests/core/find6.js +++ b/jstests/core/find6.js @@ -34,7 +34,7 @@ function f() { for (var pass = 0; pass <= 1; pass++) { f(); - q.ensureIndex({a: 1}); + q.createIndex({a: 1}); } t = db.multidim; diff --git a/jstests/core/find_and_modify_concurrent_update.js b/jstests/core/find_and_modify_concurrent_update.js index f1ac1282b49..dca7c547c18 100644 --- a/jstests/core/find_and_modify_concurrent_update.js +++ b/jstests/core/find_and_modify_concurrent_update.js @@ -19,8 +19,8 @@ for (var i = 0; i < 3; i++) { var t = db.find_and_modify_concurrent; t.drop(); - assert.commandWorked(t.ensureIndex({a: 1})); - assert.commandWorked(t.ensureIndex({b: 1})); + assert.commandWorked(t.createIndex({a: 1})); + assert.commandWorked(t.createIndex({b: 1})); assert.commandWorked(t.insert({_id: 1, a: 1, b: 1})); var join = diff --git a/jstests/core/find_dedup.js b/jstests/core/find_dedup.js index 8c628b66734..8c0f416efb1 100644 --- a/jstests/core/find_dedup.js +++ b/jstests/core/find_dedup.js @@ -22,7 +22,7 @@ function checkDedup(query, idArray) { // Deduping $or coll.drop(); -coll.ensureIndex({a: 1, b: 1}); +coll.createIndex({a: 1, b: 1}); assert.commandWorked(coll.insert({_id: 1, a: 1, b: 1})); assert.commandWorked(coll.insert({_id: 2, a: 1, b: 1})); assert.commandWorked(coll.insert({_id: 3, a: 2, b: 2})); diff --git a/jstests/core/finda.js b/jstests/core/finda.js index 0f59c4c7f3b..1525c7aaeda 100644 --- a/jstests/core/finda.js +++ b/jstests/core/finda.js @@ -11,7 +11,7 @@ t.drop(); numDocs = 200; function clearQueryPlanCache() { - t.ensureIndex({c: 1}); + t.createIndex({c: 1}); t.dropIndex({c: 1}); } @@ -92,7 +92,7 @@ function queryWithPlanTypes(withDups) { } else { t.save({_id: 0, a: 0, b: 0}); } - t.ensureIndex({a: 1, _id: 1}); // Include _id for a covered index projection. + t.createIndex({a: 1, _id: 1}); // Include _id for a covered index projection. // All plans in order. checkCursorWithBatchSize({a: {$gte: 0}}, null, 150, 150); diff --git a/jstests/core/fts2.js b/jstests/core/fts2.js index 77b6fe25bd5..7629d313b00 100644 --- a/jstests/core/fts2.js +++ b/jstests/core/fts2.js @@ -12,7 +12,7 @@ t.drop(); t.save({_id: 1, x: "az b x", y: "c d m", z: 1}); t.save({_id: 2, x: "c d y", y: "az b n", z: 2}); -t.ensureIndex({x: "text"}, {weights: {x: 10, y: 1}}); +t.createIndex({x: "text"}, {weights: {x: 10, y: 1}}); assert.eq([1, 2], queryIDS(t, "az"), "A1"); assert.eq([2, 1], queryIDS(t, "d"), "A2"); diff --git a/jstests/core/fts3.js b/jstests/core/fts3.js index 6a4c813744a..32aa3fb002a 100644 --- a/jstests/core/fts3.js +++ b/jstests/core/fts3.js @@ -12,7 +12,7 @@ t.drop(); t.save({_id: 1, x: "az b x", y: "c d m", z: 1}); t.save({_id: 2, x: "c d y", y: "az b n", z: 2}); -t.ensureIndex({x: "text", z: 1}, {weights: {x: 10, y: 1}}); +t.createIndex({x: "text", z: 1}, {weights: {x: 10, y: 1}}); assert.eq([1, 2], queryIDS(t, "az"), "A1"); assert.eq([2, 1], queryIDS(t, "d"), "A2"); diff --git a/jstests/core/fts4.js b/jstests/core/fts4.js index 16f88a7a760..ea8055eeb11 100644 --- a/jstests/core/fts4.js +++ b/jstests/core/fts4.js @@ -12,7 +12,7 @@ t.drop(); t.save({_id: 1, x: ["az", "b", "x"], y: ["c", "d", "m"], z: 1}); t.save({_id: 2, x: ["c", "d", "y"], y: ["az", "b", "n"], z: 2}); -t.ensureIndex({y: "text", z: 1}, {weights: {x: 10}}); +t.createIndex({y: "text", z: 1}, {weights: {x: 10}}); assert.eq([1, 2], queryIDS(t, "az"), "A1"); assert.eq([2, 1], queryIDS(t, "d"), "A2"); diff --git a/jstests/core/fts5.js b/jstests/core/fts5.js index 99cd6ce84bb..aa689a46ed9 100644 --- a/jstests/core/fts5.js +++ b/jstests/core/fts5.js @@ -12,7 +12,7 @@ t.drop(); t.save({_id: 1, x: [{a: "az"}, {a: "b"}, {a: "x"}], y: ["c", "d", "m"], z: 1}); t.save({_id: 2, x: [{a: "c"}, {a: "d"}, {a: "y"}], y: ["az", "b", "n"], z: 2}); -t.ensureIndex({y: "text", z: 1}, {weights: {"x.a": 10}}); +t.createIndex({y: "text", z: 1}, {weights: {"x.a": 10}}); assert.eq([1, 2], queryIDS(t, "az"), "A1"); assert.eq([2, 1], queryIDS(t, "d"), "A2"); diff --git a/jstests/core/fts6.js b/jstests/core/fts6.js index 7216fc728e9..ab757b81d59 100644 --- a/jstests/core/fts6.js +++ b/jstests/core/fts6.js @@ -7,8 +7,8 @@ var t = db.jstests_fts6; t.drop(); -t.ensureIndex({a: 1}); -t.ensureIndex({b: "text"}); +t.createIndex({a: 1}); +t.createIndex({b: "text"}); t.save({_id: 1, a: 0}); t.save({_id: 2, a: 0, b: "foo"}); diff --git a/jstests/core/fts_blog.js b/jstests/core/fts_blog.js index cdaba7860fc..2b0fe26e095 100644 --- a/jstests/core/fts_blog.js +++ b/jstests/core/fts_blog.js @@ -10,7 +10,7 @@ t.save({_id: 3, title: "knives are Fun", text: "this is a new blog i am writing. // @tags: [ // sbe_incompatible, // ] -t.ensureIndex({"title": "text", text: "text"}, {weights: {title: 10}}); +t.createIndex({"title": "text", text: "text"}, {weights: {title: 10}}); res = t.find({"$text": {"$search": "blog"}}, {score: {"$meta": "textScore"}}).sort({ score: {"$meta": "textScore"} diff --git a/jstests/core/fts_blogwild.js b/jstests/core/fts_blogwild.js index 207fea471c1..881c486edad 100644 --- a/jstests/core/fts_blogwild.js +++ b/jstests/core/fts_blogwild.js @@ -18,7 +18,7 @@ t.save({ // default weight is 1 // specify weights if you want a field to be more meaningull -t.ensureIndex({dummy: "text"}, {weights: "$**"}); +t.createIndex({dummy: "text"}, {weights: "$**"}); res = t.find({"$text": {"$search": "blog"}}); assert.eq(3, res.length(), "A1"); @@ -29,7 +29,7 @@ assert.eq(3, res.length(), "B1"); // mixing t.dropIndex("dummy_text"); assert.eq(1, t.getIndexKeys().length, "C1"); -t.ensureIndex({dummy: "text"}, {weights: {"$**": 1, title: 2}}); +t.createIndex({dummy: "text"}, {weights: {"$**": 1, title: 2}}); res = t.find({"$text": {"$search": "write"}}, {score: {"$meta": "textScore"}}).sort({ score: {"$meta": "textScore"} diff --git a/jstests/core/fts_casesensitive.js b/jstests/core/fts_casesensitive.js index 191631a6ac0..b4a730a46b5 100644 --- a/jstests/core/fts_casesensitive.js +++ b/jstests/core/fts_casesensitive.js @@ -9,7 +9,7 @@ var coll = db.fts_casesensitive; coll.drop(); assert.commandWorked(coll.insert({_id: 0, a: "The Quick Brown Fox Jumps Over The Lazy Dog"})); -assert.commandWorked(coll.ensureIndex({a: "text"})); +assert.commandWorked(coll.createIndex({a: "text"})); assert.throws(function() { queryIDS(coll, "hello", null, {$caseSensitive: "invalid"}); diff --git a/jstests/core/fts_diacritic_and_caseinsensitive.js b/jstests/core/fts_diacritic_and_caseinsensitive.js index 107ff447ec9..1b8a2d0d1e0 100644 --- a/jstests/core/fts_diacritic_and_caseinsensitive.js +++ b/jstests/core/fts_diacritic_and_caseinsensitive.js @@ -14,7 +14,7 @@ coll.drop(); assert.commandWorked(coll.insert( {_id: 0, a: "O próximo Vôo à Noite sobre o Atlântico, Põe Freqüentemente o único Médico."})); -assert.commandWorked(coll.ensureIndex({a: "text"}, {default_language: "portuguese"})); +assert.commandWorked(coll.createIndex({a: "text"}, {default_language: "portuguese"})); assert.eq([0], queryIDS(coll, "proximo voo a", null)); assert.eq([0], queryIDS(coll, "átlántico", null)); diff --git a/jstests/core/fts_diacritic_and_casesensitive.js b/jstests/core/fts_diacritic_and_casesensitive.js index 0f0e63feca4..124ec9c092d 100644 --- a/jstests/core/fts_diacritic_and_casesensitive.js +++ b/jstests/core/fts_diacritic_and_casesensitive.js @@ -15,7 +15,7 @@ coll.drop(); assert.commandWorked(coll.insert( {_id: 0, a: "O próximo Vôo à Noite sobre o Atlântico, Põe Freqüentemente o único Médico."})); -assert.commandWorked(coll.ensureIndex({a: "text"}, {default_language: "portuguese"})); +assert.commandWorked(coll.createIndex({a: "text"}, {default_language: "portuguese"})); assert.eq([0], queryIDS(coll, "próximo vôo à ", null, {$diacriticSensitive: true, $caseSensitive: true})); diff --git a/jstests/core/fts_diacriticsensitive.js b/jstests/core/fts_diacriticsensitive.js index 4440e587ed7..2396860e0db 100644 --- a/jstests/core/fts_diacriticsensitive.js +++ b/jstests/core/fts_diacriticsensitive.js @@ -14,7 +14,7 @@ coll.drop(); assert.commandWorked(coll.insert( {_id: 0, a: "O próximo vôo à noite sobre o Atlântico, põe freqüentemente o único médico."})); -assert.commandWorked(coll.ensureIndex({a: "text"}, {default_language: "portuguese"})); +assert.commandWorked(coll.createIndex({a: "text"}, {default_language: "portuguese"})); assert.throws(function() { queryIDS(coll, "hello", null, {$diacriticSensitive: "invalid"}); diff --git a/jstests/core/fts_explain.js b/jstests/core/fts_explain.js index 1f1f0a0e55b..9b87cedcc51 100644 --- a/jstests/core/fts_explain.js +++ b/jstests/core/fts_explain.js @@ -14,7 +14,7 @@ const coll = db.fts_explain; let res; coll.drop(); -res = coll.ensureIndex({content: "text"}, {default_language: "none"}); +res = coll.createIndex({content: "text"}, {default_language: "none"}); assert.commandWorked(res); res = coll.insert({content: "some data"}); diff --git a/jstests/core/fts_index.js b/jstests/core/fts_index.js index a41ea5a8dab..3080534c434 100644 --- a/jstests/core/fts_index.js +++ b/jstests/core/fts_index.js @@ -27,7 +27,7 @@ coll.getDB().createCollection(coll.getName()); // // Spec passes text-specific index validation. -assert.commandWorked(coll.ensureIndex({a: "text"}, {name: indexName, default_language: "spanish"})); +assert.commandWorked(coll.createIndex({a: "text"}, {name: indexName, default_language: "spanish"})); assert.eq(1, coll.getIndexes() .filter(function(z) { @@ -38,7 +38,7 @@ coll.dropIndexes(); // Spec fails text-specific index validation ("spanglish" unrecognized). assert.commandFailed( - coll.ensureIndex({a: "text"}, {name: indexName, default_language: "spanglish"})); + coll.createIndex({a: "text"}, {name: indexName, default_language: "spanglish"})); assert.eq(0, coll.getIndexes() .filter(function(z) { @@ -48,7 +48,7 @@ assert.eq(0, coll.dropIndexes(); // Spec passes general index validation. -assert.commandWorked(coll.ensureIndex({"$**": "text"}, {name: indexName})); +assert.commandWorked(coll.createIndex({"$**": "text"}, {name: indexName})); assert.eq(1, coll.getIndexes() .filter(function(z) { @@ -58,7 +58,7 @@ assert.eq(1, coll.dropIndexes(); // Spec fails general index validation ("a.$**" invalid field name for key). -assert.commandFailed(coll.ensureIndex({"a.$**": "text"}, {name: indexName})); +assert.commandFailed(coll.createIndex({"a.$**": "text"}, {name: indexName})); assert.eq(0, coll.getIndexes() .filter(function(z) { @@ -68,7 +68,7 @@ assert.eq(0, coll.dropIndexes(); // SERVER-19519 Spec fails if '_fts' is specified on a non-text index. -assert.commandFailed(coll.ensureIndex({_fts: 1}, {name: indexName})); +assert.commandFailed(coll.createIndex({_fts: 1}, {name: indexName})); assert.eq(0, coll.getIndexes() .filter(function(z) { @@ -76,7 +76,7 @@ assert.eq(0, }) .length); coll.dropIndexes(); -assert.commandFailed(coll.ensureIndex({_fts: "text"}, {name: indexName})); +assert.commandFailed(coll.createIndex({_fts: "text"}, {name: indexName})); assert.eq(0, coll.getIndexes() .filter(function(z) { @@ -92,22 +92,22 @@ 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.commandWorked(coll.ensureIndex({a: "text"})); +assert.commandWorked(coll.createIndex({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.commandFailed(coll.ensureIndex({a: "text"})); +assert.commandFailed(coll.createIndex({a: "text"})); coll.drop(); // Can insert documents with valid language_override into text-indexed collection. -assert.commandWorked(coll.ensureIndex({a: "text"})); +assert.commandWorked(coll.createIndex({a: "text"})); coll.insert({a: ""}); assert.commandWorked(coll.insert({a: "", language: "spanish"})); coll.drop(); // Can't insert documents with invalid language_override into text-indexed collection. -assert.commandWorked(coll.ensureIndex({a: "text"})); +assert.commandWorked(coll.createIndex({a: "text"})); assert.writeError(coll.insert({a: "", language: "spanglish"})); coll.drop(); @@ -115,69 +115,69 @@ coll.drop(); // 3. Collections may have at most one text index. // -// ensureIndex() becomes a no-op on an equivalent index spec. +// createIndex() becomes a no-op on an equivalent index spec. assert.commandWorked(coll.getDB().createCollection(coll.getName())); assert.eq(1, coll.getIndexes().length); -assert.commandWorked(coll.ensureIndex({a: 1, b: "text", c: 1})); +assert.commandWorked(coll.createIndex({a: 1, b: "text", c: 1})); assert.eq(2, coll.getIndexes().length); -assert.commandWorked(coll.ensureIndex({a: 1, b: "text", c: 1})); +assert.commandWorked(coll.createIndex({a: 1, b: "text", c: 1})); assert.eq(2, coll.getIndexes().length); -assert.commandWorked(coll.ensureIndex({a: 1, b: "text", c: 1}, {background: true})); +assert.commandWorked(coll.createIndex({a: 1, b: "text", c: 1}, {background: true})); assert.eq(2, coll.getIndexes().length); -assert.commandFailedWithCode(coll.ensureIndex({a: 1, b: 1, c: "text"}), +assert.commandFailedWithCode(coll.createIndex({a: 1, b: 1, c: "text"}), ErrorCodes.CannotCreateIndex); assert.commandFailedWithCode( - coll.ensureIndex({a: 1, _fts: "text", _ftsx: 1, c: 1}, {weights: {b: 1}}), + coll.createIndex({a: 1, _fts: "text", _ftsx: 1, c: 1}, {weights: {b: 1}}), ErrorCodes.IndexOptionsConflict); assert.eq(2, coll.getIndexes().length); -assert.commandWorked(coll.ensureIndex({a: 1, b: "text", c: 1}, {default_language: "english"})); +assert.commandWorked(coll.createIndex({a: 1, b: "text", c: 1}, {default_language: "english"})); assert.eq(2, coll.getIndexes().length); -assert.commandWorked(coll.ensureIndex({a: 1, b: "text", c: 1}, {textIndexVersion: 2})); +assert.commandWorked(coll.createIndex({a: 1, b: "text", c: 1}, {textIndexVersion: 2})); assert.eq(2, coll.getIndexes().length); -assert.commandWorked(coll.ensureIndex({a: 1, b: "text", c: 1}, {language_override: "language"})); +assert.commandWorked(coll.createIndex({a: 1, b: "text", c: 1}, {language_override: "language"})); assert.eq(2, coll.getIndexes().length); coll.drop(); // Two index specs are also considered equivalent if they differ only in 'textIndexVersion', and -// ensureIndex() becomes a no-op on repeated requests that only differ in this way. +// createIndex() becomes a no-op on repeated requests that only differ in this way. assert.commandWorked(coll.getDB().createCollection(coll.getName())); assert.eq(1, coll.getIndexes().length); -assert.commandWorked(coll.ensureIndex({a: "text"}, {textIndexVersion: 1})); +assert.commandWorked(coll.createIndex({a: "text"}, {textIndexVersion: 1})); assert.eq(2, coll.getIndexes().length); -assert.commandWorked(coll.ensureIndex({a: "text"}, {textIndexVersion: 2})); +assert.commandWorked(coll.createIndex({a: "text"}, {textIndexVersion: 2})); assert.eq(2, coll.getIndexes().length); -assert.commandWorked(coll.ensureIndex({a: "text"}, {textIndexVersion: 3})); +assert.commandWorked(coll.createIndex({a: "text"}, {textIndexVersion: 3})); assert.eq(2, coll.getIndexes().length); -assert.commandWorked(coll.ensureIndex({a: "text"})); +assert.commandWorked(coll.createIndex({a: "text"})); assert.eq(2, coll.getIndexes().length); coll.drop(); assert.commandWorked(coll.getDB().createCollection(coll.getName())); assert.eq(1, coll.getIndexes().length); -assert.commandWorked(coll.ensureIndex({a: "text"}, {textIndexVersion: 3})); +assert.commandWorked(coll.createIndex({a: "text"}, {textIndexVersion: 3})); assert.eq(2, coll.getIndexes().length); -assert.commandWorked(coll.ensureIndex({a: "text"}, {textIndexVersion: 2})); +assert.commandWorked(coll.createIndex({a: "text"}, {textIndexVersion: 2})); assert.eq(2, coll.getIndexes().length); -assert.commandWorked(coll.ensureIndex({a: "text"}, {textIndexVersion: 1})); +assert.commandWorked(coll.createIndex({a: "text"}, {textIndexVersion: 1})); assert.eq(2, coll.getIndexes().length); -assert.commandWorked(coll.ensureIndex({a: "text"})); +assert.commandWorked(coll.createIndex({a: "text"})); assert.eq(2, coll.getIndexes().length); coll.drop(); -// ensureIndex() fails if a second text index would be built. +// createIndex() fails if a second text index would be built. assert.commandWorked(coll.getDB().createCollection(coll.getName())); assert.eq(1, coll.getIndexes().length); -assert.commandWorked(coll.ensureIndex({a: 1, b: "text", c: 1})); -assert.eq(2, coll.getIndexes().length); -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}, {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"})); +assert.commandWorked(coll.createIndex({a: 1, b: "text", c: 1})); +assert.eq(2, coll.getIndexes().length); +assert.commandFailed(coll.createIndex({a: 1, _fts: "text", _ftsx: 1, c: 1}, {weights: {d: 1}})); +assert.commandFailed(coll.createIndex({a: 1, b: "text", c: 1}, {default_language: "none"})); +assert.commandFailed(coll.createIndex({a: 1, b: "text", c: 1}, {language_override: "idioma"})); +assert.commandFailed(coll.createIndex({a: 1, b: "text", c: 1}, {weights: {d: 1}})); +assert.commandFailed(coll.createIndex({a: 1, b: "text", d: 1})); +assert.commandFailed(coll.createIndex({a: 1, d: "text", c: 1})); +assert.commandFailed(coll.createIndex({b: "text"})); +assert.commandFailed(coll.createIndex({b: "text", c: 1})); +assert.commandFailed(coll.createIndex({a: 1, b: "text"})); coll.dropIndexes(); @@ -185,7 +185,7 @@ coll.dropIndexes(); // 4. Text indexes properly handle large keys. // -assert.commandWorked(coll.ensureIndex({a: "text"})); +assert.commandWorked(coll.createIndex({a: "text"})); var longstring = ""; var longstring2 = ""; @@ -201,7 +201,7 @@ coll.dropIndexes(); // // 5. Bad weights test cases. // -assert.commandFailed(coll.ensureIndex({a: 1, _fts: "text", _ftsx: 1, c: 1}, {weights: {}})); -assert.commandFailed(coll.ensureIndex({a: 1, _fts: "text", _ftsx: 1, c: 1})); +assert.commandFailed(coll.createIndex({a: 1, _fts: "text", _ftsx: 1, c: 1}, {weights: {}})); +assert.commandFailed(coll.createIndex({a: 1, _fts: "text", _ftsx: 1, c: 1})); coll.drop(); diff --git a/jstests/core/fts_index2.js b/jstests/core/fts_index2.js index 1c8454002a7..3ae6e45214e 100644 --- a/jstests/core/fts_index2.js +++ b/jstests/core/fts_index2.js @@ -14,7 +14,7 @@ coll1.drop(); coll2.drop(); assert.commandWorked(coll1.insert({a: {b: "some content"}})); -assert.commandWorked(coll1.ensureIndex({"$**": "text"})); +assert.commandWorked(coll1.createIndex({"$**": "text"})); assert.eq(1, coll1.count({$text: {$search: "content"}})); // Rename within same database. diff --git a/jstests/core/fts_index3.js b/jstests/core/fts_index3.js index 02bd9559591..0f57c7a9d80 100644 --- a/jstests/core/fts_index3.js +++ b/jstests/core/fts_index3.js @@ -12,7 +12,7 @@ var coll = db.fts_index3; // 1) Create a text index on a single field, insert a document, update the value of the field, and // verify that $text with the new value returns the document. coll.drop(); -assert.commandWorked(coll.ensureIndex({a: "text"})); +assert.commandWorked(coll.createIndex({a: "text"})); assert.commandWorked(coll.insert({a: "hello"})); assert.eq(1, coll.find({$text: {$search: "hello"}}).itcount()); assert.commandWorked(coll.update({}, {$set: {a: "world"}})); @@ -21,7 +21,7 @@ assert.eq(1, coll.find({$text: {$search: "world"}}).itcount()); // 2) Same as #1, but with a wildcard text index. coll.drop(); -assert.commandWorked(coll.ensureIndex({"$**": "text"})); +assert.commandWorked(coll.createIndex({"$**": "text"})); assert.commandWorked(coll.insert({a: "hello"})); assert.eq(1, coll.find({$text: {$search: "hello"}}).itcount()); assert.commandWorked(coll.update({}, {$set: {a: "world"}})); @@ -31,7 +31,7 @@ assert.eq(1, coll.find({$text: {$search: "world"}}).itcount()); // 3) Create a compound text index with an index prefix, insert a document, update the value of the // index prefix field, and verify that $text with the new value returns the document. coll.drop(); -assert.commandWorked(coll.ensureIndex({a: 1, b: "text"})); +assert.commandWorked(coll.createIndex({a: 1, b: "text"})); assert.commandWorked(coll.insert({a: 1, b: "hello"})); assert.eq(1, coll.find({a: 1, $text: {$search: "hello"}}).itcount()); assert.commandWorked(coll.update({}, {$set: {a: 2}})); @@ -40,7 +40,7 @@ assert.eq(1, coll.find({a: 2, $text: {$search: "hello"}}).itcount()); // 4) Same as #3, but with a wildcard text index. coll.drop(); -assert.commandWorked(coll.ensureIndex({a: 1, "$**": "text"})); +assert.commandWorked(coll.createIndex({a: 1, "$**": "text"})); assert.commandWorked(coll.insert({a: 1, b: "hello"})); assert.eq(1, coll.find({a: 1, $text: {$search: "hello"}}).itcount()); assert.commandWorked(coll.update({}, {$set: {a: 2}})); @@ -50,7 +50,7 @@ assert.eq(1, coll.find({a: 2, $text: {$search: "hello"}}).itcount()); // 5) Create a compound text index with an index suffix, insert a document, update the value of the // index suffix field, and verify that $text with the new value returns the document. coll.drop(); -assert.commandWorked(coll.ensureIndex({a: "text", b: 1})); +assert.commandWorked(coll.createIndex({a: "text", b: 1})); assert.commandWorked(coll.insert({a: "hello", b: 1})); assert.eq(1, coll.find({b: 1, $text: {$search: "hello"}}).itcount()); assert.commandWorked(coll.update({}, {$set: {b: 2}})); @@ -59,7 +59,7 @@ assert.eq(1, coll.find({b: 2, $text: {$search: "hello"}}).itcount()); // 6) Same as #5, but with a wildcard text index. coll.drop(); -assert.commandWorked(coll.ensureIndex({"$**": "text", b: 1})); +assert.commandWorked(coll.createIndex({"$**": "text", b: 1})); assert.commandWorked(coll.insert({a: "hello", b: 1})); assert.eq(1, coll.find({b: 1, $text: {$search: "hello"}}).itcount()); assert.commandWorked(coll.update({}, {$set: {b: 2}})); @@ -69,7 +69,7 @@ assert.eq(1, coll.find({b: 2, $text: {$search: "hello"}}).itcount()); // 7) Create a text index on a single field, insert a document, update the language of the document // (so as to change the stemming), and verify that $text with the new language returns the document. coll.drop(); -assert.commandWorked(coll.ensureIndex({a: "text"})); +assert.commandWorked(coll.createIndex({a: "text"})); assert.commandWorked(coll.insert({a: "testing", language: "es"})); assert.eq(1, coll.find({$text: {$search: "testing", $language: "es"}}).itcount()); assert.eq(0, coll.find({$text: {$search: "testing", $language: "en"}}).itcount()); @@ -79,7 +79,7 @@ assert.eq(1, coll.find({$text: {$search: "testing", $language: "en"}}).itcount() // 8) Same as #7, but with a wildcard text index. coll.drop(); -assert.commandWorked(coll.ensureIndex({"$**": "text"})); +assert.commandWorked(coll.createIndex({"$**": "text"})); assert.commandWorked(coll.insert({a: "testing", language: "es"})); assert.eq(1, coll.find({$text: {$search: "testing", $language: "es"}}).itcount()); assert.eq(0, coll.find({$text: {$search: "testing", $language: "en"}}).itcount()); @@ -91,7 +91,7 @@ assert.eq(1, coll.find({$text: {$search: "testing", $language: "en"}}).itcount() // subdocument (so as to change the stemming), and verify that $text with the new language returns // the document. coll.drop(); -assert.commandWorked(coll.ensureIndex({"a.b": "text"})); +assert.commandWorked(coll.createIndex({"a.b": "text"})); assert.commandWorked(coll.insert({a: {b: "testing", language: "es"}})); assert.eq(1, coll.find({$text: {$search: "testing", $language: "es"}}).itcount()); assert.eq(0, coll.find({$text: {$search: "testing", $language: "en"}}).itcount()); @@ -101,7 +101,7 @@ assert.eq(1, coll.find({$text: {$search: "testing", $language: "en"}}).itcount() // 10) Same as #9, but with a wildcard text index. coll.drop(); -assert.commandWorked(coll.ensureIndex({"$**": "text"})); +assert.commandWorked(coll.createIndex({"$**": "text"})); assert.commandWorked(coll.insert({a: {b: "testing", language: "es"}})); assert.eq(1, coll.find({$text: {$search: "testing", $language: "es"}}).itcount()); assert.eq(0, coll.find({$text: {$search: "testing", $language: "en"}}).itcount()); @@ -113,7 +113,7 @@ assert.eq(1, coll.find({$text: {$search: "testing", $language: "en"}}).itcount() // update the language of the document (so as to change the stemming), and verify that $text with // the new language returns the document. coll.drop(); -assert.commandWorked(coll.ensureIndex({a: "text"}, {language_override: "idioma"})); +assert.commandWorked(coll.createIndex({a: "text"}, {language_override: "idioma"})); assert.commandWorked(coll.insert({a: "testing", idioma: "es"})); assert.eq(1, coll.find({$text: {$search: "testing", $language: "es"}}).itcount()); assert.eq(0, coll.find({$text: {$search: "testing", $language: "en"}}).itcount()); @@ -123,7 +123,7 @@ assert.eq(1, coll.find({$text: {$search: "testing", $language: "en"}}).itcount() // 12) Same as #11, but with a wildcard text index. coll.drop(); -assert.commandWorked(coll.ensureIndex({"$**": "text"}, {language_override: "idioma"})); +assert.commandWorked(coll.createIndex({"$**": "text"}, {language_override: "idioma"})); assert.commandWorked(coll.insert({a: "testing", idioma: "es"})); assert.eq(1, coll.find({$text: {$search: "testing", $language: "es"}}).itcount()); assert.eq(0, coll.find({$text: {$search: "testing", $language: "en"}}).itcount()); diff --git a/jstests/core/fts_index_version1.js b/jstests/core/fts_index_version1.js index 8ae979c7dbe..57b7c7710b6 100644 --- a/jstests/core/fts_index_version1.js +++ b/jstests/core/fts_index_version1.js @@ -3,19 +3,19 @@ var coll = db.fts_index_version1; // Test basic English search. coll.drop(); -assert.commandWorked(coll.ensureIndex({a: "text"}, {textIndexVersion: 1})); +assert.commandWorked(coll.createIndex({a: "text"}, {textIndexVersion: 1})); assert.commandWorked(coll.insert({a: "running"})); assert.eq(1, coll.count({$text: {$search: "run"}})); // Test search with a "language alias" only recognized in textIndexVersion:1 (note that the stopword // machinery doesn't recognize these aliases). coll.drop(); -assert.commandWorked(coll.ensureIndex({a: "text"}, {default_language: "eng", textIndexVersion: 1})); +assert.commandWorked(coll.createIndex({a: "text"}, {default_language: "eng", textIndexVersion: 1})); assert.commandWorked(coll.insert({a: "running"})); assert.eq(1, coll.count({$text: {$search: "run"}})); // Test that textIndexVersion:1 indexes ignore subdocument language annotations. coll.drop(); -assert.commandWorked(coll.ensureIndex({"a.b": "text"}, {textIndexVersion: 1})); +assert.commandWorked(coll.createIndex({"a.b": "text"}, {textIndexVersion: 1})); assert.commandWorked(coll.insert({language: "none", a: {language: "english", b: "the"}})); assert.eq(1, coll.count({$text: {$search: "the", $language: "none"}})); diff --git a/jstests/core/fts_index_version2.js b/jstests/core/fts_index_version2.js index 10f803f30c6..1e579ba12cb 100644 --- a/jstests/core/fts_index_version2.js +++ b/jstests/core/fts_index_version2.js @@ -15,7 +15,7 @@ assert.commandWorked(coll.insert( {_id: 0, a: "O próximo Vôo à Noite sobre o Atlântico, Põe Freqüentemente o único Médico."})); assert.commandWorked( - coll.ensureIndex({a: "text"}, {default_language: "portuguese", textIndexVersion: 2})); + coll.createIndex({a: "text"}, {default_language: "portuguese", textIndexVersion: 2})); assert.eq([0], queryIDS(coll, "próximo vôo à ", null)); assert.eq([0], queryIDS(coll, "atlântico", null)); diff --git a/jstests/core/fts_mix.js b/jstests/core/fts_mix.js index abfdcc6aefd..cdaaf1d17ff 100644 --- a/jstests/core/fts_mix.js +++ b/jstests/core/fts_mix.js @@ -77,7 +77,7 @@ tc.save({ // -------------------------------------------- INDEXING & WEIGHTING ------------------------------- // start with basic index, one item with default weight -tc.ensureIndex({"title": "text"}); +tc.createIndex({"title": "text"}); // test the single result case.. res = tc.find({"$text": {"$search": "Victoria"}}); @@ -87,19 +87,19 @@ assert.eq(10, res[0]._id); tc.dropIndexes(); // now let's see about multiple fields, with specific weighting -tc.ensureIndex({"title": "text", "text": "text"}, {weights: {"title": 10}}); +tc.createIndex({"title": "text", "text": "text"}, {weights: {"title": 10}}); assert(resultsEq([9, 7, 8], queryIDS(tc, "members physics"))); tc.dropIndexes(); // test all-1 weighting with "$**" -tc.ensureIndex({"$**": "text"}); +tc.createIndex({"$**": "text"}); assert(resultsEq([2, 8, 7], queryIDS(tc, "family tea estate"))); tc.dropIndexes(); // non-1 weight on "$**" + other weight specified for some field -tc.ensureIndex({"$**": "text"}, {weights: {"$**": 10, "text": 2}}); +tc.createIndex({"$**": "text"}, {weights: {"$**": 10, "text": 2}}); assert(resultsEq([7, 5], queryIDS(tc, "Olympic Games gold medal"))); tc.dropIndexes(); @@ -108,7 +108,7 @@ tc.dropIndexes(); // ------------------------------------------ // go back to "$**": 1, "title": 10.. and test more specific "search" functionality! -tc.ensureIndex({"$**": "text"}, {weights: {"title": 10}}); +tc.createIndex({"$**": "text"}, {weights: {"title": 10}}); // -------------------------------------------- STEMMING ------------------------------------------- diff --git a/jstests/core/fts_partition1.js b/jstests/core/fts_partition1.js index 055f574baf1..efc148da675 100644 --- a/jstests/core/fts_partition1.js +++ b/jstests/core/fts_partition1.js @@ -13,7 +13,7 @@ t.insert({_id: 2, x: 1, y: "bar"}); t.insert({_id: 3, x: 2, y: "foo"}); t.insert({_id: 4, x: 2, y: "bar"}); -t.ensureIndex({x: 1, y: "text"}); +t.createIndex({x: 1, y: "text"}); assert.throws(function() { const cursor = t.find({"$text": {"$search": "foo"}}); diff --git a/jstests/core/fts_partition_no_multikey.js b/jstests/core/fts_partition_no_multikey.js index af28380a804..b819c3abfbd 100644 --- a/jstests/core/fts_partition_no_multikey.js +++ b/jstests/core/fts_partition_no_multikey.js @@ -1,7 +1,7 @@ t = db.fts_partition_no_multikey; t.drop(); -t.ensureIndex({x: 1, y: "text"}); +t.createIndex({x: 1, y: "text"}); assert.commandWorked(t.insert({x: 5, y: "this is fun"})); diff --git a/jstests/core/fts_phrase.js b/jstests/core/fts_phrase.js index eae0a1c268d..dfe9d3692af 100644 --- a/jstests/core/fts_phrase.js +++ b/jstests/core/fts_phrase.js @@ -11,7 +11,7 @@ t.save({_id: 1, title: "my blog post", text: "i am writing a blog. yay"}); t.save({_id: 2, title: "my 2nd post", text: "this is a new blog i am typing. yay"}); t.save({_id: 3, title: "knives are Fun", text: "this is a new blog i am writing. yay"}); -t.ensureIndex({"title": "text", text: "text"}, {weights: {title: 10}}); +t.createIndex({"title": "text", text: "text"}, {weights: {title: 10}}); res = t.find({"$text": {"$search": "blog write"}}, {score: {"$meta": "textScore"}}).sort({ score: {"$meta": "textScore"} diff --git a/jstests/core/geo1.js b/jstests/core/geo1.js index 7917799377e..8a80f59d692 100644 --- a/jstests/core/geo1.js +++ b/jstests/core/geo1.js @@ -19,10 +19,10 @@ assert.commandWorked(t.insert({zip: "94061", loc: [37.463911, 122.23396]})); // test "2d" has to be first assert.eq(1, t.getIndexKeys().length, "S1"); -t.ensureIndex({zip: 1, loc: "2d"}); +t.createIndex({zip: 1, loc: "2d"}); assert.eq(1, t.getIndexKeys().length, "S2"); -t.ensureIndex(idx); +t.createIndex(idx); assert.eq(2, t.getIndexKeys().length, "S3"); assert.eq(3, t.count(), "B1"); @@ -42,5 +42,5 @@ assert.eq("06525", t.find({loc: wb.loc})[0].zip, "C3"); t.drop(); -t.ensureIndex({loc: "2d"}, {min: -500, max: 500, bits: 4}); +t.createIndex({loc: "2d"}, {min: -500, max: 500, bits: 4}); assert.commandWorked(t.insert({loc: [200, 200]})); diff --git a/jstests/core/geo10.js b/jstests/core/geo10.js index c33f90cdfbd..b330ce52911 100644 --- a/jstests/core/geo10.js +++ b/jstests/core/geo10.js @@ -10,7 +10,7 @@ coll = db.geo10; coll.drop(); -assert.commandWorked(db.geo10.ensureIndex({c: '2d', t: 1}, {min: 0, max: Math.pow(2, 40)})); +assert.commandWorked(db.geo10.createIndex({c: '2d', t: 1}, {min: 0, max: Math.pow(2, 40)})); assert.eq(2, db.geo10.getIndexes().length, "A3"); assert.commandWorked(db.geo10.insert({c: [1, 1], t: 1})); diff --git a/jstests/core/geo2.js b/jstests/core/geo2.js index 01a4c467339..b0552e2f773 100644 --- a/jstests/core/geo2.js +++ b/jstests/core/geo2.js @@ -18,7 +18,7 @@ t.insert(arr); assert.eq(t.count(), 100 * 100); assert.eq(t.count(), n - 1); -t.ensureIndex({loc: "2d"}); +t.createIndex({loc: "2d"}); function a(cur) { var total = 0; diff --git a/jstests/core/geo3.js b/jstests/core/geo3.js index e75c9b14245..40a3d9a5e75 100644 --- a/jstests/core/geo3.js +++ b/jstests/core/geo3.js @@ -19,7 +19,7 @@ t.insert(arr); assert.eq(t.count(), 100 * 100); assert.eq(t.count(), n - 1); -t.ensureIndex({loc: "2d"}); +t.createIndex({loc: "2d"}); // Test the "query" parameter in $geoNear. @@ -52,7 +52,7 @@ function testFiltering(msg) { testFiltering("just loc"); assert.commandWorked(t.dropIndex({loc: "2d"})); -assert.commandWorked(t.ensureIndex({loc: "2d", a: 1})); +assert.commandWorked(t.createIndex({loc: "2d", a: 1})); res = t.aggregate([ {$geoNear: {near: [50, 50], distanceField: "dist", query: {a: 2}}}, @@ -64,7 +64,7 @@ res.forEach(doc => assert.eq(2, doc.a, tojson(doc))); testFiltering("loc and a"); assert.commandWorked(t.dropIndex({loc: "2d", a: 1})); -assert.commandWorked(t.ensureIndex({loc: "2d", b: 1})); +assert.commandWorked(t.createIndex({loc: "2d", b: 1})); testFiltering("loc and b"); diff --git a/jstests/core/geo6.js b/jstests/core/geo6.js index d6b43771b2c..0ee06508ea2 100644 --- a/jstests/core/geo6.js +++ b/jstests/core/geo6.js @@ -6,7 +6,7 @@ t = db.geo6; t.drop(); -t.ensureIndex({loc: "2d"}); +t.createIndex({loc: "2d"}); assert.eq(0, t.find().itcount(), "pre0"); assert.eq(0, t.find({loc: {$near: [50, 50]}}).itcount(), "pre1"); diff --git a/jstests/core/geo7.js b/jstests/core/geo7.js index 4316c8d6c03..9d1b7f574ca 100644 --- a/jstests/core/geo7.js +++ b/jstests/core/geo7.js @@ -6,13 +6,13 @@ t.insert({_id: 2, y: [1, 1], z: 3}); t.insert({_id: 3, y: [1, 1], z: 4}); t.insert({_id: 4, y: [1, 1], z: 5}); -t.ensureIndex({y: "2d", z: 1}); +t.createIndex({y: "2d", z: 1}); assert.eq(1, t.find({y: [1, 1], z: 3}).itcount(), "A1"); t.dropIndex({y: "2d", z: 1}); -t.ensureIndex({y: "2d"}); +t.createIndex({y: "2d"}); assert.eq(1, t.find({y: [1, 1], z: 3}).itcount(), "A2"); t.insert({_id: 5, y: 5}); diff --git a/jstests/core/geo9.js b/jstests/core/geo9.js index eacd30f9a6d..4204c842987 100644 --- a/jstests/core/geo9.js +++ b/jstests/core/geo9.js @@ -14,8 +14,8 @@ t.save({_id: 4, a: [50, 50], b: [10, 10]}); t.save({_id: 5, a: [51, 51], b: [11, 11]}); t.save({_id: 6, a: [52, 52], b: [12, 12]}); -t.ensureIndex({a: "2d"}); -t.ensureIndex({b: "2d"}); +t.createIndex({a: "2d"}); +t.createIndex({b: "2d"}); function check(field) { var q = {}; diff --git a/jstests/core/geo_2d_explain.js b/jstests/core/geo_2d_explain.js index 370ef47e708..109c5618795 100644 --- a/jstests/core/geo_2d_explain.js +++ b/jstests/core/geo_2d_explain.js @@ -13,7 +13,7 @@ var n = 1000; // insert n documents with integer _id, a can be 1-5, loc is close to [40, 40] t.drop(); -t.ensureIndex({loc: "2d", _id: 1}); +t.createIndex({loc: "2d", _id: 1}); var x = 40; var y = 40; diff --git a/jstests/core/geo_2d_with_geojson_point.js b/jstests/core/geo_2d_with_geojson_point.js index bb35fccd9da..3930f3c2c96 100644 --- a/jstests/core/geo_2d_with_geojson_point.js +++ b/jstests/core/geo_2d_with_geojson_point.js @@ -4,7 +4,7 @@ var t = db.geo_2d_with_geojson_point; t.drop(); -t.ensureIndex({loc: '2d'}); +t.createIndex({loc: '2d'}); var geoJSONPoint = {type: 'Point', coordinates: [0, 0]}; diff --git a/jstests/core/geo_allowedcomparisons.js b/jstests/core/geo_allowedcomparisons.js index c1ef4efcba1..01795941533 100644 --- a/jstests/core/geo_allowedcomparisons.js +++ b/jstests/core/geo_allowedcomparisons.js @@ -33,7 +33,7 @@ oldPolygon = [[-5, -5], [-5, 5], [5, 5], [5, -5], [-5, -5]]; oldCenter = [[0, 0], 1]; t.drop(); -t.ensureIndex({geo: "2d"}); +t.createIndex({geo: "2d"}); // 2d doesn't know what to do w/this assert.writeError(t.insert({geo: geojsonPoint})); // Old points are OK. @@ -102,7 +102,7 @@ t.dropIndex({geo: "2d"}); runTests(); // 2dsphere index now. -assert.commandWorked(t.ensureIndex({geo: "2dsphere"})); +assert.commandWorked(t.createIndex({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 0f27de02e49..8a4e81283f8 100644 --- a/jstests/core/geo_array0.js +++ b/jstests/core/geo_array0.js @@ -16,7 +16,7 @@ function test(index) { assert.commandWorked(res); if (index) { - assert.commandWorked(t.ensureIndex({loc: "2d", zip: 1})); + assert.commandWorked(t.createIndex({loc: "2d", zip: 1})); assert.eq(2, t.getIndexKeys().length); } diff --git a/jstests/core/geo_array1.js b/jstests/core/geo_array1.js index 08b6060f3cc..6066ed1dc6f 100644 --- a/jstests/core/geo_array1.js +++ b/jstests/core/geo_array1.js @@ -21,7 +21,7 @@ function test(index) { } if (index) { - t.ensureIndex({loc: "2d"}); + t.createIndex({loc: "2d"}); } // Pull them back diff --git a/jstests/core/geo_array2.js b/jstests/core/geo_array2.js index d2a197891e6..2a7a1303e0c 100644 --- a/jstests/core/geo_array2.js +++ b/jstests/core/geo_array2.js @@ -27,7 +27,7 @@ for (var i = -1; i < 2; i++) { } } -assert.commandWorked(t.ensureIndex({loc: "2d", type: 1})); +assert.commandWorked(t.createIndex({loc: "2d", type: 1})); print("Starting testing phase... "); diff --git a/jstests/core/geo_big_polygon.js b/jstests/core/geo_big_polygon.js index eb2a24ad719..db0d00cf6ff 100644 --- a/jstests/core/geo_big_polygon.js +++ b/jstests/core/geo_big_polygon.js @@ -10,7 +10,7 @@ var coll = db.geo_big_polygon; coll.drop(); -// coll.ensureIndex({ loc : "2dsphere" }); +// coll.createIndex({ loc : "2dsphere" }); var bigCRS = {type: "name", properties: {name: "urn:x-mongodb:crs:strictwinding:EPSG:4326"}}; @@ -56,7 +56,7 @@ assert.eq(coll.find({loc: {$geoIntersects: {$geometry: bigPoly20}}}).count(), 4) assert.eq(coll.find({loc: {$geoWithin: {$geometry: bigPoly20Comp}}}).count(), 1); assert.eq(coll.find({loc: {$geoIntersects: {$geometry: bigPoly20Comp}}}).count(), 2); -assert.commandWorked(coll.ensureIndex({loc: "2dsphere"})); +assert.commandWorked(coll.createIndex({loc: "2dsphere"})); assert.eq(coll.find({loc: {$geoWithin: {$geometry: bigPoly20}}}).count(), 3); assert.eq(coll.find({loc: {$geoIntersects: {$geometry: bigPoly20}}}).count(), 4); @@ -81,11 +81,11 @@ assert.eq(coll.find({loc: {$geoWithin: {$geometry: bigPoly20Comp}}}).count(), 1) assert.eq(coll.find({loc: {$geoIntersects: {$geometry: bigPoly20Comp}}}).count(), 2); // 2. Building index fails due to big polygon -assert.commandFailed(coll.ensureIndex({loc: "2dsphere"})); +assert.commandFailed(coll.createIndex({loc: "2dsphere"})); // 3. After removing big polygon, index builds successfully assert.commandWorked(coll.remove({_id: "bigPoly10"})); -assert.commandWorked(coll.ensureIndex({loc: "2dsphere"})); +assert.commandWorked(coll.createIndex({loc: "2dsphere"})); // 4. With index, insert fails. assert.writeError(coll.insert({_id: "bigPoly10", loc: bigPoly10})); diff --git a/jstests/core/geo_big_polygon2.js b/jstests/core/geo_big_polygon2.js index 80339cb4fed..53e0631e791 100644 --- a/jstests/core/geo_big_polygon2.js +++ b/jstests/core/geo_big_polygon2.js @@ -560,7 +560,7 @@ const nsidedPolys = [ ]; // Populate with 2dsphere index -assert.commandWorked(coll.ensureIndex({geo: "2dsphere"}), "create 2dsphere index"); +assert.commandWorked(coll.createIndex({geo: "2dsphere"}), "create 2dsphere index"); // Insert objects into collection objects.forEach(function(o) { @@ -573,10 +573,10 @@ objects.forEach(function(o) { }); // Try creating other index types -assert.commandWorked(coll.ensureIndex({geo: "2dsphere", a: 1}), "compound index, geo"); +assert.commandWorked(coll.createIndex({geo: "2dsphere", a: 1}), "compound index, geo"); // These other index types will fail because of the GeoJSON documents -assert.commandFailed(coll.ensureIndex({geo: "2dsphere", a: "text"}), "compound index, geo & text"); -assert.commandFailed(coll.ensureIndex({geo: "2d"}), "2d index"); +assert.commandFailed(coll.createIndex({geo: "2dsphere", a: "text"}), "compound index, geo & text"); +assert.commandFailed(coll.createIndex({geo: "2d"}), "2d index"); totalObjects = coll.count(); @@ -589,7 +589,7 @@ indexes.forEach(function(index) { if (index != "none") { // Create index - assert.commandWorked(coll.ensureIndex({geo: index}), "create " + index + " index"); + assert.commandWorked(coll.createIndex({geo: index}), "create " + index + " index"); } // These polygons should not be queryable diff --git a/jstests/core/geo_big_polygon3.js b/jstests/core/geo_big_polygon3.js index a55ce87c3d6..cd4591dd66a 100644 --- a/jstests/core/geo_big_polygon3.js +++ b/jstests/core/geo_big_polygon3.js @@ -63,7 +63,7 @@ var bigPoly = { }; // 2dsphere index required -assert.commandWorked(coll.ensureIndex({geo: "2dsphere"}), "2dsphere index"); +assert.commandWorked(coll.createIndex({geo: "2dsphere"}), "2dsphere index"); // $nearSphere on big polygon should fail assert.throws(function() { @@ -222,7 +222,7 @@ assert.eq(totalDocs, "crs84CRS or epsg4326CRS intersects"); // Add index and look again for stored point & spherical CRS documents -assert.commandWorked(coll.ensureIndex({geo: "2dsphere"}), "2dsphere index"); +assert.commandWorked(coll.createIndex({geo: "2dsphere"}), "2dsphere index"); assert.eq(totalDocs, coll.count({geo: {$geoWithin: {$geometry: poly}}}), diff --git a/jstests/core/geo_borders.js b/jstests/core/geo_borders.js index 8eac710db0f..01989a445bc 100644 --- a/jstests/core/geo_borders.js +++ b/jstests/core/geo_borders.js @@ -24,11 +24,11 @@ overallMax = 1; // Create a point index slightly smaller than the points we have var res = - t.ensureIndex({loc: "2d"}, {max: overallMax - epsilon / 2, min: overallMin + epsilon / 2}); + t.createIndex({loc: "2d"}, {max: overallMax - epsilon / 2, min: overallMin + epsilon / 2}); assert.commandFailed(res); // Create a point index only slightly bigger than the points we have -res = t.ensureIndex({loc: "2d"}, {max: overallMax + epsilon, min: overallMin - epsilon}); +res = t.createIndex({loc: "2d"}, {max: overallMax + epsilon, min: overallMin - epsilon}); assert.commandWorked(res); // ************ diff --git a/jstests/core/geo_box1.js b/jstests/core/geo_box1.js index 300e65c2dc6..28fe85c83cf 100644 --- a/jstests/core/geo_box1.js +++ b/jstests/core/geo_box1.js @@ -14,7 +14,7 @@ for (x = 0; x <= 20; x++) { } } -t.ensureIndex({loc: "2d"}); +t.createIndex({loc: "2d"}); searches = [ [[1, 2], [4, 5]], diff --git a/jstests/core/geo_box2.js b/jstests/core/geo_box2.js index f0f99b15ea0..e4e51ec9e10 100644 --- a/jstests/core/geo_box2.js +++ b/jstests/core/geo_box2.js @@ -14,10 +14,10 @@ for (i = 1; i < 10; i++) { } } -t.ensureIndex({"loc": "2d"}); +t.createIndex({"loc": "2d"}); assert.eq(9, t.find({loc: {$within: {$box: [[4, 4], [6, 6]]}}}).itcount(), "A1"); t.dropIndex({"loc": "2d"}); -t.ensureIndex({"loc": "2d"}, {"min": 0, "max": 10}); +t.createIndex({"loc": "2d"}, {"min": 0, "max": 10}); assert.eq(9, t.find({loc: {$within: {$box: [[4, 4], [6, 6]]}}}).itcount(), "B1"); diff --git a/jstests/core/geo_box3.js b/jstests/core/geo_box3.js index 7f9dd12ea60..4a91ffb0d1d 100644 --- a/jstests/core/geo_box3.js +++ b/jstests/core/geo_box3.js @@ -7,7 +7,7 @@ t = db.geo_box3; t.drop(); t.insert({point: {x: -15000000, y: 10000000}}); -t.ensureIndex({point: "2d"}, {min: -21000000, max: 21000000}); +t.createIndex({point: "2d"}, {min: -21000000, max: 21000000}); var c = t.find({point: {"$within": {"$box": [[-20000000, 7000000], [0, 15000000]]}}}); assert.eq(1, c.count(), "A1"); @@ -15,7 +15,7 @@ assert.eq(1, c.count(), "A1"); t = db.geo_box3; t.drop(); t.insert({point: {x: -15, y: 10}}); -t.ensureIndex({point: "2d"}, {min: -21, max: 21}); +t.createIndex({point: "2d"}, {min: -21, max: 21}); var c = t.find({point: {"$within": {"$box": [[-20, 7], [0, 15]]}}}); assert.eq(1, c.count(), "B1"); @@ -24,13 +24,13 @@ assert.eq(1, c.count(), "B1"); t = db.geo_box3; t.drop(); t.insert({point: {x: 1.0, y: 1.0}}); -t.ensureIndex({point: "2d"}, {min: -2, max: 2}); +t.createIndex({point: "2d"}, {min: -2, max: 2}); var c = t.find({point: {"$within": {"$box": [[.1, .1], [1.99, 1.99]]}}}); assert.eq(1, c.count(), "C1"); t = db.geo_box3; t.drop(); t.insert({point: {x: 3.9, y: 3.9}}); -t.ensureIndex({point: "2d"}, {min: 0, max: 4}); +t.createIndex({point: "2d"}, {min: 0, max: 4}); var c = t.find({point: {"$within": {"$box": [[2.05, 2.05], [3.99, 3.99]]}}}); assert.eq(1, c.count(), "D1"); diff --git a/jstests/core/geo_center_sphere1.js b/jstests/core/geo_center_sphere1.js index df3ea9bb36c..cbef0b4302d 100644 --- a/jstests/core/geo_center_sphere1.js +++ b/jstests/core/geo_center_sphere1.js @@ -45,7 +45,7 @@ function test(index) { assert.commandWorked(bulk.execute()); if (index) { - t.ensureIndex({loc: index}); + t.createIndex({loc: index}); } for (i = 0; i < searches.length; i++) { diff --git a/jstests/core/geo_center_sphere2.js b/jstests/core/geo_center_sphere2.js index 4a263cba259..2b5e8be5cab 100644 --- a/jstests/core/geo_center_sphere2.js +++ b/jstests/core/geo_center_sphere2.js @@ -50,7 +50,7 @@ for (var test = 0; test < numTests; test++) { do { t.drop(); startPoint = randomPoint(); - t.ensureIndex({loc: "2d"}, {bits: bits}); + t.createIndex({loc: "2d"}, {bits: bits}); } while (!pointIsOK(startPoint, radius)); var pointsIn = 0; diff --git a/jstests/core/geo_circle1.js b/jstests/core/geo_circle1.js index 65d2a467eab..0df085bcb4d 100644 --- a/jstests/core/geo_circle1.js +++ b/jstests/core/geo_circle1.js @@ -29,7 +29,7 @@ for (x = 0; x <= 20; x++) { } } -t.ensureIndex({loc: "2d"}); +t.createIndex({loc: "2d"}); for (i = 0; i < searches.length; i++) { // print( tojson( searches[i] ) + "\t" + correct[i].length ) diff --git a/jstests/core/geo_circle2.js b/jstests/core/geo_circle2.js index 30a826b4f27..6be02377259 100644 --- a/jstests/core/geo_circle2.js +++ b/jstests/core/geo_circle2.js @@ -7,7 +7,7 @@ t = db.geo_circle2; t.drop(); -t.ensureIndex({loc: "2d", categories: 1}, {"name": "placesIdx", "min": -100, "max": 100}); +t.createIndex({loc: "2d", categories: 1}, {"name": "placesIdx", "min": -100, "max": 100}); t.insert( {"uid": 368900, "loc": {"x": -36, "y": -8}, "categories": ["sports", "hotel", "restaurant"]}); diff --git a/jstests/core/geo_circle2a.js b/jstests/core/geo_circle2a.js index b084d1027ec..f647bdc82ea 100644 --- a/jstests/core/geo_circle2a.js +++ b/jstests/core/geo_circle2a.js @@ -6,7 +6,7 @@ var coll = db.geo_circle2a; coll.drop(); coll.insert({p: [1112, 3473], t: [{k: 'a', v: 'b'}, {k: 'c', v: 'd'}]}); -coll.ensureIndex({p: '2d', 't.k': 1}, {min: 0, max: 10000}); +coll.createIndex({p: '2d', 't.k': 1}, {min: 0, max: 10000}); // Succeeds, since on direct lookup should not use the index assert(1 == coll.find({p: [1112, 3473], 't.k': 'a'}).count(), "A"); @@ -18,7 +18,7 @@ coll.drop(); coll.insert({point: [1, 10], tags: [{k: 'key', v: 'value'}, {k: 'key2', v: 123}]}); coll.insert({point: [1, 10], tags: [{k: 'key', v: 'value'}]}); -coll.ensureIndex({point: "2d", "tags.k": 1, "tags.v": 1}); +coll.createIndex({point: "2d", "tags.k": 1, "tags.v": 1}); // Succeeds, since should now lookup multi-keys correctly assert(2 == coll.find({point: {$within: {$box: [[0, 0], [12, 12]]}}}).count(), "C"); @@ -31,7 +31,7 @@ coll.drop(); coll.insert({point: [1, 10], tags: [{k: {'hello': 'world'}, v: 'value'}, {k: 'key2', v: 123}]}); coll.insert({point: [1, 10], tags: [{k: 'key', v: 'value'}]}); -coll.ensureIndex({point: "2d", "tags.k": 1, "tags.v": 1}); +coll.createIndex({point: "2d", "tags.k": 1, "tags.v": 1}); // Succeeds, should be able to look up the complex element assert(1 == diff --git a/jstests/core/geo_circle3.js b/jstests/core/geo_circle3.js index 3be564cd180..e931e96783d 100644 --- a/jstests/core/geo_circle3.js +++ b/jstests/core/geo_circle3.js @@ -14,7 +14,7 @@ db.places.save({"_id": n++, "loc": {"x": 4.9999, "y": 52.0001}}); db.places.save({"_id": n++, "loc": {"x": 5.0001, "y": 52.0001}}); db.places.save({"_id": n++, "loc": {"x": 4.9999, "y": 51.9999}}); db.places.save({"_id": n++, "loc": {"x": 5.0001, "y": 51.9999}}); -db.places.ensureIndex({loc: "2d"}); +db.places.createIndex({loc: "2d"}); radius = 0.0001; center = [5, 52]; // print(db.places.find({"loc" : {"$within" : {"$center" : [center, radius]}}}).count()) diff --git a/jstests/core/geo_circle4.js b/jstests/core/geo_circle4.js index 1feb72a2e48..04ce685db38 100644 --- a/jstests/core/geo_circle4.js +++ b/jstests/core/geo_circle4.js @@ -18,7 +18,7 @@ function test(index) { db.server848.save({"_id": 8, "loc": {"x": 4.9999, "y": 51.9999}}); db.server848.save({"_id": 9, "loc": {"x": 5.0001, "y": 51.9999}}); if (index) { - db.server848.ensureIndex({loc: "2d"}); + db.server848.createIndex({loc: "2d"}); } r = db.server848.find({"loc": {"$within": {"$center": [center, radius]}}}, {_id: 1}); assert.eq(5, r.count(), "A1"); diff --git a/jstests/core/geo_circle5.js b/jstests/core/geo_circle5.js index 34b3773ad00..27b973a8ede 100644 --- a/jstests/core/geo_circle5.js +++ b/jstests/core/geo_circle5.js @@ -8,7 +8,7 @@ db.server1238.drop(); db.server1238.remove({}); db.server1238.save({loc: [5000000, 900000], id: 1}); db.server1238.save({loc: [5000000, 900000], id: 2}); -db.server1238.ensureIndex({loc: "2d"}, {min: -21000000, max: 21000000}); +db.server1238.createIndex({loc: "2d"}, {min: -21000000, max: 21000000}); db.server1238.save({loc: [5000000, 900000], id: 3}); db.server1238.save({loc: [5000000, 900000], id: 4}); diff --git a/jstests/core/geo_exactfetch.js b/jstests/core/geo_exactfetch.js index 68ecc9941ae..93b0b7afcda 100644 --- a/jstests/core/geo_exactfetch.js +++ b/jstests/core/geo_exactfetch.js @@ -7,7 +7,7 @@ t.drop(); function test(indexname) { assert.eq(1, t.find({lon_lat: [-71.34895, 42.46037]}).itcount(), indexname); - t.ensureIndex({lon_lat: indexname, population: -1}); + t.createIndex({lon_lat: indexname, population: -1}); assert.eq(2, t.find({lon_lat: {$nearSphere: [-71.34895, 42.46037]}}).itcount(), indexname); assert.eq(1, t.find({lon_lat: [-71.34895, 42.46037]}).itcount(), indexname); t.dropIndex({lon_lat: indexname, population: -1}); diff --git a/jstests/core/geo_fiddly_box.js b/jstests/core/geo_fiddly_box.js index 6c2adbe66c6..9f5a9e8d6c4 100644 --- a/jstests/core/geo_fiddly_box.js +++ b/jstests/core/geo_fiddly_box.js @@ -11,7 +11,7 @@ t = db.geo_fiddly_box; t.drop(); -t.ensureIndex({loc: "2d"}); +t.createIndex({loc: "2d"}); t.insert({"loc": [3, 1]}); t.insert({"loc": [3, 0.5]}); @@ -35,7 +35,7 @@ step = 1; numItems = 0; t.drop(); -t.ensureIndex({loc: "2d"}, {max: max + epsilon / 2, min: min - epsilon / 2}); +t.createIndex({loc: "2d"}, {max: max + epsilon / 2, min: min - epsilon / 2}); for (var x = min; x <= max; x += step) { for (var y = min; y <= max; y += step) { diff --git a/jstests/core/geo_fiddly_box2.js b/jstests/core/geo_fiddly_box2.js index 6a40b5032b5..a0f87203163 100644 --- a/jstests/core/geo_fiddly_box2.js +++ b/jstests/core/geo_fiddly_box2.js @@ -16,18 +16,18 @@ t.insert({"letter": "B", "position": [2, 0]}); t.insert({"letter": "L", "position": [3, 0]}); t.insert({"letter": "E", "position": [4, 0]}); -t.ensureIndex({position: "2d"}); +t.createIndex({position: "2d"}); result = t.find({"position": {"$within": {"$box": [[-3, -1], [0, 1]]}}}); assert.eq(4, result.count()); t.dropIndex({position: "2d"}); -t.ensureIndex({position: "2d"}, {min: -10000000, max: 10000000}); +t.createIndex({position: "2d"}, {min: -10000000, max: 10000000}); result = t.find({"position": {"$within": {"$box": [[-3, -1], [0, 1]]}}}); assert.eq(4, result.count()); t.dropIndex({position: "2d"}); -t.ensureIndex({position: "2d"}, {min: -1000000000, max: 1000000000}); +t.createIndex({position: "2d"}, {min: -1000000000, max: 1000000000}); result = t.find({"position": {"$within": {"$box": [[-3, -1], [0, 1]]}}}); assert.eq(4, result.count()); diff --git a/jstests/core/geo_invalid_2d_params.js b/jstests/core/geo_invalid_2d_params.js index b538d430a66..33419302b47 100644 --- a/jstests/core/geo_invalid_2d_params.js +++ b/jstests/core/geo_invalid_2d_params.js @@ -1,8 +1,8 @@ var t = db.geo_invalid_2d_params; t.drop(); -assert.commandFailed(t.ensureIndex({loc: "2d"}, {bits: 33})); -assert.commandFailed(t.ensureIndex({loc: "2d"}, {min: -1, max: -1})); -assert.commandFailed(t.ensureIndex({loc: "2d"}, {bits: -1})); -assert.commandFailed(t.ensureIndex({loc: "2d"}, {min: 10, max: 9})); -assert.commandWorked(t.ensureIndex({loc: "2d"}, {bits: 1, min: -1, max: 1})); +assert.commandFailed(t.createIndex({loc: "2d"}, {bits: 33})); +assert.commandFailed(t.createIndex({loc: "2d"}, {min: -1, max: -1})); +assert.commandFailed(t.createIndex({loc: "2d"}, {bits: -1})); +assert.commandFailed(t.createIndex({loc: "2d"}, {min: 10, max: 9})); +assert.commandWorked(t.createIndex({loc: "2d"}, {bits: 1, min: -1, max: 1})); diff --git a/jstests/core/geo_mindistance.js b/jstests/core/geo_mindistance.js index 33153e62008..8994892c77d 100644 --- a/jstests/core/geo_mindistance.js +++ b/jstests/core/geo_mindistance.js @@ -56,7 +56,7 @@ for (var x = 0; x <= 10; x += 1) { } } -t.ensureIndex({loc: "2dsphere"}); +t.createIndex({loc: "2dsphere"}); var n_docs = t.count(), geoJSONPoint = {type: 'Point', coordinates: [0, 0]}, legacyPoint = [0, 0]; diff --git a/jstests/core/geo_mindistance_boundaries.js b/jstests/core/geo_mindistance_boundaries.js index 9d556b341ac..7024cfa2ec9 100644 --- a/jstests/core/geo_mindistance_boundaries.js +++ b/jstests/core/geo_mindistance_boundaries.js @@ -9,7 +9,7 @@ t.drop(); t.insert({loc: [1, 0]}); // 1 degree of longitude from origin. /* $minDistance is supported for 2dsphere index only, not 2d */ -t.ensureIndex({loc: "2dsphere"}); +t.createIndex({loc: "2dsphere"}); // // Useful constants. diff --git a/jstests/core/geo_multikey0.js b/jstests/core/geo_multikey0.js index 827dd9a41a1..27075a779ee 100644 --- a/jstests/core/geo_multikey0.js +++ b/jstests/core/geo_multikey0.js @@ -11,7 +11,7 @@ assert.eq( // Check that conflicting constraints are satisfied by parallel array elements with a 2d index on // loc. if (0) { // SERVER-3793 - t.ensureIndex({loc: '2d'}); + t.createIndex({loc: '2d'}); assert.eq( 1, t.count({loc: {x: 20, y: 30}, $and: [{loc: {$gt: {x: 20, y: 35}, $lt: {x: 20, y: 34}}}]})); @@ -26,6 +26,6 @@ assert.eq(1, t.count({loc: [20, 30], x: {$gt: 1.7, $lt: 1.2}})); // Check that conflicting constraints are satisfied by parallel array elements of x with a 2d index // on loc,x. if (0) { // SERVER-3793 - t.ensureIndex({loc: '2d', x: 1}); + t.createIndex({loc: '2d', x: 1}); assert.eq(1, t.count({loc: [20, 30], x: {$gt: 1.7, $lt: 1.2}})); } diff --git a/jstests/core/geo_multikey1.js b/jstests/core/geo_multikey1.js index 9c092f4ec31..e6d0ec086da 100644 --- a/jstests/core/geo_multikey1.js +++ b/jstests/core/geo_multikey1.js @@ -12,7 +12,7 @@ for (i = 0; i < 10; ++i) { t.save({loc: locArr, a: arr, b: arr, c: arr}); // Parallel arrays are allowed for geo indexes. -assert.commandWorked(t.ensureIndex({loc: '2d', a: 1, b: 1, c: 1})); +assert.commandWorked(t.createIndex({loc: '2d', a: 1, b: 1, c: 1})); // Parallel arrays are not allowed for normal indexes. -assert.commandFailed(t.ensureIndex({loc: 1, a: 1, b: 1, c: 1})); +assert.commandFailed(t.createIndex({loc: 1, a: 1, b: 1, c: 1})); diff --git a/jstests/core/geo_multinest0.js b/jstests/core/geo_multinest0.js index 6c0106d70df..b76c18dbd5c 100644 --- a/jstests/core/geo_multinest0.js +++ b/jstests/core/geo_multinest0.js @@ -16,7 +16,7 @@ var res = t.insert({zip: "10003", data: [{loc: [30, 30], type: "home"}, {loc: [50, 50], type: "work"}]}); assert.commandWorked(res); -assert.commandWorked(t.ensureIndex({"data.loc": "2d", zip: 1})); +assert.commandWorked(t.createIndex({"data.loc": "2d", zip: 1})); assert.eq(2, t.getIndexKeys().length); res = @@ -41,7 +41,7 @@ t.insert({zip: "10002", data: [{loc: [20, 20], type: "home"}, {loc: [50, 50], ty res = t.insert({zip: "10003", data: [{loc: [{x: 30, y: 30}, [50, 50]], type: "home"}]}); assert(!res.hasWriteError()); -assert.commandWorked(t.ensureIndex({"data.loc": "2d", zip: 1})); +assert.commandWorked(t.createIndex({"data.loc": "2d", zip: 1})); assert.eq(2, t.getIndexKeys().length); res = diff --git a/jstests/core/geo_multinest1.js b/jstests/core/geo_multinest1.js index d033cfa86b8..a3fb424829e 100644 --- a/jstests/core/geo_multinest1.js +++ b/jstests/core/geo_multinest1.js @@ -16,7 +16,7 @@ var res = t.insert({zip: "10003", data: [{loc: [30, 30], type: "home"}, {loc: [49, 49], type: "work"}]}); assert.commandWorked(res); -assert.commandWorked(t.ensureIndex({"data.loc": "2d", zip: 1})); +assert.commandWorked(t.createIndex({"data.loc": "2d", zip: 1})); assert.eq(2, t.getIndexKeys().length); res = diff --git a/jstests/core/geo_near_bounds_overflow.js b/jstests/core/geo_near_bounds_overflow.js index ff674e89052..1d13d568220 100644 --- a/jstests/core/geo_near_bounds_overflow.js +++ b/jstests/core/geo_near_bounds_overflow.js @@ -13,7 +13,7 @@ function testBounds(min, max) { // Handle case where either 1. indexLambda will fail but not throw. We are asserting it // works, so the outer lambda generates an exception. 2. indexLambda itself will throw. const indexLambda = function(t) { - return t.ensureIndex({loc: '2d'}, indexBounds); + return t.createIndex({loc: '2d'}, indexBounds); }; const assertLambda = function(t, lambda) { assert.commandWorked(lambda(t)); diff --git a/jstests/core/geo_near_random1.js b/jstests/core/geo_near_random1.js index b6350e6c6a7..52dc1e34cbb 100644 --- a/jstests/core/geo_near_random1.js +++ b/jstests/core/geo_near_random1.js @@ -34,7 +34,7 @@ test.testPt(test.mkPt(), opts); // Test $nearSphere with a 2dsphere index assert.commandWorked(db.geo_near_random1.dropIndex({loc: '2d'})); -assert.commandWorked(db.geo_near_random1.ensureIndex({loc: '2dsphere'})); +assert.commandWorked(db.geo_near_random1.createIndex({loc: '2dsphere'})); test.testPt([0, 0], opts); test.testPt(test.mkPt(), opts); test.testPt(test.mkPt(), opts); diff --git a/jstests/core/geo_near_random2.js b/jstests/core/geo_near_random2.js index c524e7a7da4..4ffa95cffae 100644 --- a/jstests/core/geo_near_random2.js +++ b/jstests/core/geo_near_random2.js @@ -38,7 +38,7 @@ test.testPt(test.mkPt(0.8), opts); // Test $nearSphere with 2dsphere index assert.commandWorked(db.geo_near_random2.dropIndex({loc: '2d'})); -assert.commandWorked(db.geo_near_random2.ensureIndex({loc: '2dsphere'})); +assert.commandWorked(db.geo_near_random2.createIndex({loc: '2dsphere'})); test.testPt([0, 0], opts); test.testPt(test.mkPt(0.8), opts); test.testPt(test.mkPt(0.8), opts); diff --git a/jstests/core/geo_nearwithin.js b/jstests/core/geo_nearwithin.js index 37d963b3ddc..6ded21dbd83 100644 --- a/jstests/core/geo_nearwithin.js +++ b/jstests/core/geo_nearwithin.js @@ -13,7 +13,7 @@ for (var x = -points; x < points; x += 1) { } } -assert.commandWorked(t.ensureIndex({geo: "2d"})); +assert.commandWorked(t.createIndex({geo: "2d"})); const runQuery = (center) => t.find({$and: [{geo: {$near: [0, 0]}}, {geo: {$within: {$center: center}}}]}).toArray(); diff --git a/jstests/core/geo_oob_sphere.js b/jstests/core/geo_oob_sphere.js index 3a878f06b78..08a10758c77 100644 --- a/jstests/core/geo_oob_sphere.js +++ b/jstests/core/geo_oob_sphere.js @@ -15,7 +15,7 @@ assert.commandWorked(coll.insert({loc: {x: 30, y: 89}})); assert.commandWorked(coll.insert({loc: {x: 30, y: 89}})); assert.commandWorked(coll.insert({loc: {x: 30, y: 91}})); -assert.commandWorked(coll.ensureIndex({loc: "2d"})); +assert.commandWorked(coll.createIndex({loc: "2d"})); assert.throws(function() { coll.find({loc: {$nearSphere: [30, 91], $maxDistance: 0.25}}).count(); diff --git a/jstests/core/geo_operator_crs.js b/jstests/core/geo_operator_crs.js index cab73fedb0f..6118c4efcc7 100644 --- a/jstests/core/geo_operator_crs.js +++ b/jstests/core/geo_operator_crs.js @@ -14,7 +14,7 @@ coll.drop(); // Test 2dsphere index // -assert.commandWorked(coll.ensureIndex({geo: "2dsphere"})); +assert.commandWorked(coll.createIndex({geo: "2dsphere"})); var legacyZeroPt = [0, 0]; var jsonZeroPt = {type: "Point", coordinates: [0, 0]}; @@ -42,7 +42,7 @@ assert.commandWorked(coll.dropIndexes()); // Test 2d Index // -assert.commandWorked(coll.ensureIndex({geo: "2d"})); +assert.commandWorked(coll.createIndex({geo: "2d"})); assert.commandWorked(coll.insert({geo: legacy90Pt})); @@ -55,7 +55,7 @@ assert.close(result[0].dis, Math.PI / 2); // Test with a 2d and 2dsphere index using the aggregation $geoNear stage. // -assert.commandWorked(coll.ensureIndex({geo: "2dsphere"})); +assert.commandWorked(coll.createIndex({geo: "2dsphere"})); result = coll.aggregate({$geoNear: {near: jsonZeroPt, distanceField: "dis"}}).toArray(); assert.close(result[0].dis, (Math.PI / 2) * earthRadiusMeters); }()); diff --git a/jstests/core/geo_or.js b/jstests/core/geo_or.js index 04caca0e106..d571e3ad6e3 100644 --- a/jstests/core/geo_or.js +++ b/jstests/core/geo_or.js @@ -15,7 +15,7 @@ t.save({loc: q}); var indexname = "2dsphere"; -t.ensureIndex({loc: indexname}); +t.createIndex({loc: indexname}); assert.eq(1, t.find({loc: p}).itcount(), indexname); @@ -87,7 +87,7 @@ t.dropIndexes(); var indexname = "2d"; -t.ensureIndex({loc: indexname}); +t.createIndex({loc: indexname}); assert.eq(2, t.find({ diff --git a/jstests/core/geo_poly_edge.js b/jstests/core/geo_poly_edge.js index 971483e9eef..eee43bfc55c 100644 --- a/jstests/core/geo_poly_edge.js +++ b/jstests/core/geo_poly_edge.js @@ -8,7 +8,7 @@ var coll = db.getCollection('jstests_geo_poly_edge'); coll.drop(); -coll.ensureIndex({loc: "2d"}); +coll.createIndex({loc: "2d"}); coll.insert({loc: [10, 10]}); coll.insert({loc: [10, -10]}); diff --git a/jstests/core/geo_poly_line.js b/jstests/core/geo_poly_line.js index 3eff8d12496..49e394d140e 100644 --- a/jstests/core/geo_poly_line.js +++ b/jstests/core/geo_poly_line.js @@ -12,7 +12,7 @@ t.insert({loc: [2, 0]}); t.insert({loc: [3, 0]}); t.insert({loc: [4, 0]}); -t.ensureIndex({loc: "2d"}); +t.createIndex({loc: "2d"}); printjson(t.find({loc: {"$within": {"$polygon": [[0, 0], [2, 0], [4, 0]]}}}).toArray()); diff --git a/jstests/core/geo_polygon1.js b/jstests/core/geo_polygon1.js index 34b0cafa1d4..3d6d2ad81b2 100644 --- a/jstests/core/geo_polygon1.js +++ b/jstests/core/geo_polygon1.js @@ -13,7 +13,7 @@ for (x = 1; x < 9; x++) { } } -t.ensureIndex({loc: "2d"}); +t.createIndex({loc: "2d"}); triangle = [[0, 0], [1, 1], [0, 2]]; @@ -50,7 +50,7 @@ pacman = [ ]; t.save({loc: [1, 3]}); // Add a point that's in -assert.commandWorked(t.ensureIndex({loc: "2d"})); +assert.commandWorked(t.createIndex({loc: "2d"})); assert.eq(1, t.find({loc: {$within: {$polygon: pacman}}}).count(), "Pacman single point"); diff --git a/jstests/core/geo_polygon2.js b/jstests/core/geo_polygon2.js index e5dc6d4e941..7a6ad0aedb5 100644 --- a/jstests/core/geo_polygon2.js +++ b/jstests/core/geo_polygon2.js @@ -231,7 +231,7 @@ for (var test = 0; test < numTests; test++) { } } - var res = t.ensureIndex({loc: "2d"}, {bits: 1 + bits, max: bounds[1], min: bounds[0]}); + var res = t.createIndex({loc: "2d"}, {bits: 1 + bits, max: bounds[1], min: bounds[0]}); assert.commandWorked(res); t.insert({loc: allPointsIn}); diff --git a/jstests/core/geo_queryoptimizer.js b/jstests/core/geo_queryoptimizer.js index 56653551ba7..17b3c5997f2 100644 --- a/jstests/core/geo_queryoptimizer.js +++ b/jstests/core/geo_queryoptimizer.js @@ -6,7 +6,7 @@ t = db.geo_qo1; t.drop(); -t.ensureIndex({loc: "2d"}); +t.createIndex({loc: "2d"}); t.insert({'issue': 0}); t.insert({'issue': 1}); diff --git a/jstests/core/geo_regex0.js b/jstests/core/geo_regex0.js index 1add7f4e0c3..7629c193ea2 100644 --- a/jstests/core/geo_regex0.js +++ b/jstests/core/geo_regex0.js @@ -4,7 +4,7 @@ t = db.regex0; t.drop(); -t.ensureIndex({point: '2d', words: 1}); +t.createIndex({point: '2d', words: 1}); t.insert({point: [1, 1], words: ['foo', 'bar']}); regex = { diff --git a/jstests/core/geo_s2cursorlimitskip.js b/jstests/core/geo_s2cursorlimitskip.js index f599ccd5b62..3413314fd27 100644 --- a/jstests/core/geo_s2cursorlimitskip.js +++ b/jstests/core/geo_s2cursorlimitskip.js @@ -15,7 +15,7 @@ var testDB = db.getSiblingDB("geo_s2cursorlimitskip"); var t = testDB.geo_s2getmmm; t.drop(); -t.ensureIndex({geo: "2dsphere"}); +t.createIndex({geo: "2dsphere"}); Random.setRandomSeed(); var random = Random.rand; diff --git a/jstests/core/geo_s2dedupnear.js b/jstests/core/geo_s2dedupnear.js index bbf92ded8d7..0619d307bfa 100644 --- a/jstests/core/geo_s2dedupnear.js +++ b/jstests/core/geo_s2dedupnear.js @@ -6,7 +6,7 @@ t = db.geo_s2dedupnear; t.drop(); -t.ensureIndex({geo: "2dsphere"}); +t.createIndex({geo: "2dsphere"}); var x = { "type": "Polygon", "coordinates": [[[100.0, 0.0], [101.0, 0.0], [101.0, 1.0], [100.0, 1.0], [100.0, 0.0]]] diff --git a/jstests/core/geo_s2descindex.js b/jstests/core/geo_s2descindex.js index 4a945895c57..c4ebb435a55 100644 --- a/jstests/core/geo_s2descindex.js +++ b/jstests/core/geo_s2descindex.js @@ -34,7 +34,7 @@ for (var t = 0; t < descriptors.length; t++) { jsTest.log("Trying 2dsphere index with descriptor " + tojson(descriptor)); coll.drop(); - coll.ensureIndex(descriptor); + coll.createIndex(descriptor); coll.insert(docA); coll.insert(docB); @@ -55,7 +55,7 @@ for (var t = 0; t < descriptors.length; t++) { jsTest.log("Trying case found in wild..."); coll.drop(); -coll.ensureIndex({coordinates: "2dsphere", field: -1}); +coll.createIndex({coordinates: "2dsphere", field: -1}); coll.insert({coordinates: [-118.240013, 34.073893]}); var query = { coordinates: {$geoWithin: {$centerSphere: [[-118.240013, 34.073893], 0.44915760491198753]}}, diff --git a/jstests/core/geo_s2dupe_points.js b/jstests/core/geo_s2dupe_points.js index 2514cdbf4c1..18550b0bbbb 100644 --- a/jstests/core/geo_s2dupe_points.js +++ b/jstests/core/geo_s2dupe_points.js @@ -7,7 +7,7 @@ // ] t = db.geo_s2dupe_points; t.drop(); -t.ensureIndex({geo: "2dsphere"}); +t.createIndex({geo: "2dsphere"}); function testDuplicates(shapeName, shapeWithDupes, shapeWithoutDupes) { // insert a doc with dupes diff --git a/jstests/core/geo_s2edgecases.js b/jstests/core/geo_s2edgecases.js index 3dabfdf0bcb..6e4633f58c8 100644 --- a/jstests/core/geo_s2edgecases.js +++ b/jstests/core/geo_s2edgecases.js @@ -51,7 +51,7 @@ penguin2 = { }; t.insert({geo: penguin2}); -t.ensureIndex({geo: "2dsphere", nonGeo: 1}); +t.createIndex({geo: "2dsphere", nonGeo: 1}); res = t.find({"geo": {"$geoIntersects": {"$geometry": roundworldpoint}}}); assert.eq(res.count(), 2); diff --git a/jstests/core/geo_s2exact.js b/jstests/core/geo_s2exact.js index 2c8571c0830..92ce551d873 100644 --- a/jstests/core/geo_s2exact.js +++ b/jstests/core/geo_s2exact.js @@ -5,7 +5,7 @@ t.drop(); function test(geometry) { t.insert({geo: geometry}); assert.eq(1, t.find({geo: geometry}).itcount(), tojson(geometry)); - t.ensureIndex({geo: "2dsphere"}); + t.createIndex({geo: "2dsphere"}); assert.eq(1, t.find({geo: geometry}).itcount(), tojson(geometry)); t.dropIndex({geo: "2dsphere"}); } diff --git a/jstests/core/geo_s2explain.js b/jstests/core/geo_s2explain.js index 842c6eb22c8..9ae76163485 100644 --- a/jstests/core/geo_s2explain.js +++ b/jstests/core/geo_s2explain.js @@ -11,7 +11,7 @@ var point1 = {loc: {type: "Point", coordinates: [10, 10]}}; var point2 = {loc: {type: "Point", coordinates: [10.001, 10]}}; assert.commandWorked(t.insert([point1, point2])); -assert.commandWorked(t.ensureIndex({loc: "2dsphere"})); +assert.commandWorked(t.createIndex({loc: "2dsphere"})); var explain = t.find({loc: {$nearSphere: {type: "Point", coordinates: [10, 10]}}}) .limit(1) diff --git a/jstests/core/geo_s2holesameasshell.js b/jstests/core/geo_s2holesameasshell.js index 5407fe45c26..0b3f8ea35ec 100644 --- a/jstests/core/geo_s2holesameasshell.js +++ b/jstests/core/geo_s2holesameasshell.js @@ -1,7 +1,7 @@ // If polygons have holes, the holes cannot be equal to the entire geometry. var t = db.geo_s2holessameasshell; t.drop(); -t.ensureIndex({geo: "2dsphere"}); +t.createIndex({geo: "2dsphere"}); var centerPoint = {"type": "Point", "coordinates": [0.5, 0.5]}; var edgePoint = {"type": "Point", "coordinates": [0, 0.5]}; diff --git a/jstests/core/geo_s2index.js b/jstests/core/geo_s2index.js index ecc20c7e637..328b43d04ab 100644 --- a/jstests/core/geo_s2index.js +++ b/jstests/core/geo_s2index.js @@ -10,7 +10,7 @@ someline = { "coordinates": [[40, 5], [40, 5], [40, 5], [41, 6], [41, 6]] }; t.insert({geo: someline, nonGeo: "someline"}); -t.ensureIndex({geo: "2dsphere"}); +t.createIndex({geo: "2dsphere"}); foo = t.find({geo: {$geoIntersects: {$geometry: {type: "Point", coordinates: [40, 5]}}}}).next(); assert.eq(foo.geo, someline); t.dropIndex({geo: "2dsphere"}); @@ -56,7 +56,7 @@ somepoly = { }; t.insert({geo: somepoly, nonGeo: "somepoly"}); -var res = t.ensureIndex({geo: "2dsphere", nonGeo: 1}); +var res = t.createIndex({geo: "2dsphere", nonGeo: 1}); // We have a point without any geo data. Don't error. assert.commandWorked(res); @@ -86,7 +86,7 @@ assert.eq(res.itcount(), 1); // Don't crash mongod if we give it bad input. t.drop(); -t.ensureIndex({loc: "2dsphere", x: 1}); +t.createIndex({loc: "2dsphere", x: 1}); t.save({loc: [0, 0]}); assert.throws(function() { return t.count({loc: {$foo: [0, 0]}}); @@ -102,7 +102,7 @@ assert.throws(function() { // If we specify a datum, it has to be valid (WGS84). t.drop(); -t.ensureIndex({loc: "2dsphere"}); +t.createIndex({loc: "2dsphere"}); res = t.insert({ loc: {type: 'Point', coordinates: [40, 5], crs: {type: 'name', properties: {name: 'EPSG:2000'}}} }); @@ -127,36 +127,36 @@ assert.commandWorked(res); // 0 <= coarsestIndexedLevel <= finestIndexedLevel <= 30. t.drop(); t.save({loc: [0, 0]}); -res = t.ensureIndex({loc: "2dsphere"}, {finestIndexedLevel: 17, coarsestIndexedLevel: 5}); +res = t.createIndex({loc: "2dsphere"}, {finestIndexedLevel: 17, coarsestIndexedLevel: 5}); assert.commandWorked(res); // Ensure the index actually works at a basic level assert.neq(null, t.findOne({loc: {$geoNear: {$geometry: {type: 'Point', coordinates: [0, 0]}}}})); t.drop(); t.save({loc: [0, 0]}); -res = t.ensureIndex({loc: "2dsphere"}, {finestIndexedLevel: 31, coarsestIndexedLevel: 5}); +res = t.createIndex({loc: "2dsphere"}, {finestIndexedLevel: 31, coarsestIndexedLevel: 5}); assert.commandFailed(res); t.drop(); t.save({loc: [0, 0]}); -res = t.ensureIndex({loc: "2dsphere"}, {finestIndexedLevel: 30, coarsestIndexedLevel: 0}); +res = t.createIndex({loc: "2dsphere"}, {finestIndexedLevel: 30, coarsestIndexedLevel: 0}); assert.commandWorked(res); // Ensure the index actually works at a basic level assert.neq(null, t.findOne({loc: {$geoNear: {$geometry: {type: 'Point', coordinates: [0, 0]}}}})); t.drop(); t.save({loc: [0, 0]}); -res = t.ensureIndex({loc: "2dsphere"}, {finestIndexedLevel: 30, coarsestIndexedLevel: -1}); +res = t.createIndex({loc: "2dsphere"}, {finestIndexedLevel: 30, coarsestIndexedLevel: -1}); assert.commandFailed(res); // SERVER-21491 Verify that 2dsphere index options require correct types. -res = t.ensureIndex({loc: '2dsphere'}, {'2dsphereIndexVersion': 'NOT_A_NUMBER'}); +res = t.createIndex({loc: '2dsphere'}, {'2dsphereIndexVersion': 'NOT_A_NUMBER'}); assert.commandFailed(res); -res = t.ensureIndex({loc: '2dsphere'}, {finestIndexedLevel: 'NOT_A_NUMBER'}); +res = t.createIndex({loc: '2dsphere'}, {finestIndexedLevel: 'NOT_A_NUMBER'}); assert.commandFailedWithCode(res, ErrorCodes.TypeMismatch); -res = t.ensureIndex({loc: '2dsphere'}, {coarsestIndexedLevel: 'NOT_A_NUMBER'}); +res = t.createIndex({loc: '2dsphere'}, {coarsestIndexedLevel: 'NOT_A_NUMBER'}); assert.commandFailedWithCode(res, ErrorCodes.TypeMismatch); // Ensure polygon which previously triggered an assertion error in SERVER-19674 diff --git a/jstests/core/geo_s2indexoldformat.js b/jstests/core/geo_s2indexoldformat.js index 43974f695cb..ffe472464d4 100644 --- a/jstests/core/geo_s2indexoldformat.js +++ b/jstests/core/geo_s2indexoldformat.js @@ -9,7 +9,7 @@ t.insert({geo: [41, 6], nonGeo: ["pointB"]}); t.insert({geo: [41, 6]}); t.insert({geo: {x: 40.6, y: 5.4}}); -t.ensureIndex({geo: "2dsphere", nonGeo: 1}); +t.createIndex({geo: "2dsphere", nonGeo: 1}); res = t.find({"geo": {"$geoIntersects": {"$geometry": {x: 40, y: 5}}}}); assert.eq(res.count(), 1); diff --git a/jstests/core/geo_s2indexversion1.js b/jstests/core/geo_s2indexversion1.js index a06670ab220..2df90bb1235 100644 --- a/jstests/core/geo_s2indexversion1.js +++ b/jstests/core/geo_s2indexversion1.js @@ -15,27 +15,27 @@ coll.drop(); // var res; -res = coll.ensureIndex({geo: "2dsphere"}, {"2dsphereIndexVersion": -1}); +res = coll.createIndex({geo: "2dsphere"}, {"2dsphereIndexVersion": -1}); assert.commandFailed(res); coll.drop(); -res = coll.ensureIndex({geo: "2dsphere"}, {"2dsphereIndexVersion": 0}); +res = coll.createIndex({geo: "2dsphere"}, {"2dsphereIndexVersion": 0}); assert.commandFailed(res); coll.drop(); -res = coll.ensureIndex({geo: "2dsphere"}, {"2dsphereIndexVersion": 4}); +res = coll.createIndex({geo: "2dsphere"}, {"2dsphereIndexVersion": 4}); assert.commandFailed(res); coll.drop(); -res = coll.ensureIndex({geo: "2dsphere"}, {"2dsphereIndexVersion": Infinity}); +res = coll.createIndex({geo: "2dsphere"}, {"2dsphereIndexVersion": Infinity}); assert.commandFailed(res); coll.drop(); -res = coll.ensureIndex({geo: "2dsphere"}, {"2dsphereIndexVersion": "foo"}); +res = coll.createIndex({geo: "2dsphere"}, {"2dsphereIndexVersion": "foo"}); assert.commandFailed(res); coll.drop(); -res = coll.ensureIndex({geo: "2dsphere"}, {"2dsphereIndexVersion": {a: 1}}); +res = coll.createIndex({geo: "2dsphere"}, {"2dsphereIndexVersion": {a: 1}}); assert.commandFailed(res); coll.drop(); @@ -43,31 +43,31 @@ coll.drop(); // Index build should succeed for valid values of "2dsphereIndexVersion". // -res = coll.ensureIndex({geo: "2dsphere"}); +res = coll.createIndex({geo: "2dsphere"}); assert.commandWorked(res); coll.drop(); -res = coll.ensureIndex({geo: "2dsphere"}, {"2dsphereIndexVersion": 1}); +res = coll.createIndex({geo: "2dsphere"}, {"2dsphereIndexVersion": 1}); assert.commandWorked(res); coll.drop(); -res = coll.ensureIndex({geo: "2dsphere"}, {"2dsphereIndexVersion": NumberInt(1)}); +res = coll.createIndex({geo: "2dsphere"}, {"2dsphereIndexVersion": NumberInt(1)}); assert.commandWorked(res); coll.drop(); -res = coll.ensureIndex({geo: "2dsphere"}, {"2dsphereIndexVersion": NumberLong(1)}); +res = coll.createIndex({geo: "2dsphere"}, {"2dsphereIndexVersion": NumberLong(1)}); assert.commandWorked(res); coll.drop(); -res = coll.ensureIndex({geo: "2dsphere"}, {"2dsphereIndexVersion": 2}); +res = coll.createIndex({geo: "2dsphere"}, {"2dsphereIndexVersion": 2}); assert.commandWorked(res); coll.drop(); -res = coll.ensureIndex({geo: "2dsphere"}, {"2dsphereIndexVersion": NumberInt(2)}); +res = coll.createIndex({geo: "2dsphere"}, {"2dsphereIndexVersion": NumberInt(2)}); assert.commandWorked(res); coll.drop(); -res = coll.ensureIndex({geo: "2dsphere"}, {"2dsphereIndexVersion": NumberLong(2)}); +res = coll.createIndex({geo: "2dsphere"}, {"2dsphereIndexVersion": NumberLong(2)}); assert.commandWorked(res); coll.drop(); @@ -75,7 +75,7 @@ coll.drop(); // {2dsphereIndexVersion: 3} should be the default for new indexes. // -res = coll.ensureIndex({geo: "2dsphere"}); +res = coll.createIndex({geo: "2dsphere"}); assert.commandWorked(res); var specObj = coll.getIndexes().filter(function(z) { return z.name == "geo_2dsphere"; @@ -85,26 +85,26 @@ coll.drop(); // // Two index specs are considered equivalent if they differ only in '2dsphereIndexVersion', and -// ensureIndex() should become a no-op on repeated requests that only differ in this way. +// createIndex() should become a no-op on repeated requests that only differ in this way. // assert.commandWorked(coll.getDB().createCollection(coll.getName())); assert.eq(1, coll.getIndexes().length); -assert.commandWorked(coll.ensureIndex({geo: "2dsphere"}, {"2dsphereIndexVersion": 1})); +assert.commandWorked(coll.createIndex({geo: "2dsphere"}, {"2dsphereIndexVersion": 1})); assert.eq(2, coll.getIndexes().length); -assert.commandWorked(coll.ensureIndex({geo: "2dsphere"}, {"2dsphereIndexVersion": 2})); +assert.commandWorked(coll.createIndex({geo: "2dsphere"}, {"2dsphereIndexVersion": 2})); assert.eq(2, coll.getIndexes().length); -assert.commandWorked(coll.ensureIndex({geo: "2dsphere"})); +assert.commandWorked(coll.createIndex({geo: "2dsphere"})); assert.eq(2, coll.getIndexes().length); coll.drop(); assert.commandWorked(coll.getDB().createCollection(coll.getName())); assert.eq(1, coll.getIndexes().length); -assert.commandWorked(coll.ensureIndex({geo: "2dsphere"}, {"2dsphereIndexVersion": 2})); +assert.commandWorked(coll.createIndex({geo: "2dsphere"}, {"2dsphereIndexVersion": 2})); assert.eq(2, coll.getIndexes().length); -assert.commandWorked(coll.ensureIndex({geo: "2dsphere"}, {"2dsphereIndexVersion": 1})); +assert.commandWorked(coll.createIndex({geo: "2dsphere"}, {"2dsphereIndexVersion": 1})); assert.eq(2, coll.getIndexes().length); -assert.commandWorked(coll.ensureIndex({geo: "2dsphere"})); +assert.commandWorked(coll.createIndex({geo: "2dsphere"})); assert.eq(2, coll.getIndexes().length); coll.drop(); @@ -175,7 +175,7 @@ var geometryCollectionDoc = { }; // {2dsphereIndexVersion: 2} indexes allow all supported GeoJSON objects. -res = coll.ensureIndex({geo: "2dsphere"}, {"2dsphereIndexVersion": 2}); +res = coll.createIndex({geo: "2dsphere"}, {"2dsphereIndexVersion": 2}); assert.commandWorked(res); res = coll.insert(pointDoc); assert.commandWorked(res); @@ -194,7 +194,7 @@ assert.commandWorked(res); coll.drop(); // {2dsphereIndexVersion: 1} indexes allow only Point, LineString, and Polygon. -res = coll.ensureIndex({geo: "2dsphere"}, {"2dsphereIndexVersion": 1}); +res = coll.createIndex({geo: "2dsphere"}, {"2dsphereIndexVersion": 1}); assert.commandWorked(res); res = coll.insert(pointDoc); assert.commandWorked(res); diff --git a/jstests/core/geo_s2intersection.js b/jstests/core/geo_s2intersection.js index 25479a58349..50f26a6aa83 100644 --- a/jstests/core/geo_s2intersection.js +++ b/jstests/core/geo_s2intersection.js @@ -1,6 +1,6 @@ var t = db.geo_s2intersectinglines; t.drop(); -t.ensureIndex({geo: "2dsphere"}); +t.createIndex({geo: "2dsphere"}); /**All the tests in this file are generally confirming intersections based upon * these three geo objects. @@ -143,7 +143,7 @@ assert.eq(result[0]['name'], 'canonPoly'); // Case 12: Make sure that we properly handle and $and of two // $geoIntersects predicates. t.drop(); -t.ensureIndex({a: "2dsphere"}); +t.createIndex({a: "2dsphere"}); t.insert({a: {type: "Polygon", coordinates: [[[0, 0], [3, 6], [6, 0], [0, 0]]]}}); var firstPoint = {$geometry: {type: "Point", coordinates: [3.0, 1.0]}}; diff --git a/jstests/core/geo_s2largewithin.js b/jstests/core/geo_s2largewithin.js index 4723bb4833e..156b711bdff 100644 --- a/jstests/core/geo_s2largewithin.js +++ b/jstests/core/geo_s2largewithin.js @@ -5,7 +5,7 @@ // ] t = db.geo_s2largewithin; t.drop(); -t.ensureIndex({geo: "2dsphere"}); +t.createIndex({geo: "2dsphere"}); testPoint = { name: "origin", diff --git a/jstests/core/geo_s2meridian.js b/jstests/core/geo_s2meridian.js index 47f4fb08a6a..5842000e998 100644 --- a/jstests/core/geo_s2meridian.js +++ b/jstests/core/geo_s2meridian.js @@ -1,6 +1,6 @@ t = db.geo_s2meridian; t.drop(); -t.ensureIndex({geo: "2dsphere"}); +t.createIndex({geo: "2dsphere"}); /** * Test 1: check that intersection works on the meridian. We insert a line @@ -26,7 +26,7 @@ result = t.find({geo: {$geoIntersects: {$geometry: lineAlongMeridian}}}); assert.eq(result.itcount(), 1); t.drop(); -t.ensureIndex({geo: "2dsphere"}); +t.createIndex({geo: "2dsphere"}); /* * Test 2: check that within work across the meridian. We insert points * on the meridian, and immediately on either side, and confirm that a poly @@ -55,7 +55,7 @@ result = t.find({geo: {$geoWithin: {$geometry: meridianCrossingPoly}}}); assert.eq(result.itcount(), 3); t.drop(); -t.ensureIndex({geo: "2dsphere"}); +t.createIndex({geo: "2dsphere"}); /* * Test 3: Check that near works around the meridian. Insert two points, one * closer, but across the meridian, and confirm they both come back, and diff --git a/jstests/core/geo_s2multi.js b/jstests/core/geo_s2multi.js index 28034ad8ba6..9f4208d51aa 100644 --- a/jstests/core/geo_s2multi.js +++ b/jstests/core/geo_s2multi.js @@ -1,7 +1,7 @@ t = db.geo_s2multi; t.drop(); -t.ensureIndex({geo: "2dsphere"}); +t.createIndex({geo: "2dsphere"}); // Let's try the examples in the GeoJSON spec. // @tags: [ diff --git a/jstests/core/geo_s2near.js b/jstests/core/geo_s2near.js index c61e16927ff..2cd1df5cbbc 100644 --- a/jstests/core/geo_s2near.js +++ b/jstests/core/geo_s2near.js @@ -14,7 +14,7 @@ goldenPoint = { coordinates: [31.0, 41.0] }; t.insert({geo: goldenPoint}); -t.ensureIndex({geo: "2dsphere"}); +t.createIndex({geo: "2dsphere"}); resNear = t.aggregate([ {$geoNear: {near: [30, 40], distanceField: "d", spherical: true, includeLocs: "loc"}}, @@ -40,7 +40,7 @@ origin = { "coordinates": [lng, lat] }; -t.ensureIndex({geo: "2dsphere"}); +t.createIndex({geo: "2dsphere"}); // Near only works when the query is a point. someline = { diff --git a/jstests/core/geo_s2nearComplex.js b/jstests/core/geo_s2nearComplex.js index d7f4fffabc1..40bc9b72445 100644 --- a/jstests/core/geo_s2nearComplex.js +++ b/jstests/core/geo_s2nearComplex.js @@ -6,7 +6,7 @@ var t = db.get_s2nearcomplex; t.drop(); -t.ensureIndex({geo: "2dsphere"}); +t.createIndex({geo: "2dsphere"}); /* Short names for math operations */ Random.setRandomSeed(); @@ -176,7 +176,7 @@ print("Total points:"); print(t.find(query).itcount()); t.drop(); -t.ensureIndex({geo: "2dsphere"}); +t.createIndex({geo: "2dsphere"}); // Test a uniform distribution with 5 gaps each with 10 points missing. uniformPointsWithGaps(origin, 1000, 1, 10.0, 5, 10); @@ -188,7 +188,7 @@ print("Total points:"); print(t.find(query).itcount()); t.drop(); -t.ensureIndex({geo: "2dsphere"}); +t.createIndex({geo: "2dsphere"}); // Test a uniform distribution with 5 clusters each with between 10 and 100 points. uniformPointsWithClusters(origin, 1000, 1, 10.0, 5, 10, 100); @@ -201,7 +201,7 @@ print("Total points:"); print(t.find(query).itcount()); t.drop(); -t.ensureIndex({geo: "2dsphere"}); +t.createIndex({geo: "2dsphere"}); // Test a uniform near search with origin around the pole. @@ -225,7 +225,7 @@ print(t.find({geo: {$geoNear: {$geometry: originGeo}}}) assert.eq(t.find({geo: {$geoNear: {$geometry: originGeo}}}).itcount(), 50); t.drop(); -t.ensureIndex({geo: "2dsphere"}); +t.createIndex({geo: "2dsphere"}); // Center point near the meridian originGeo = { @@ -247,7 +247,7 @@ print(t.find({geo: {$geoNear: {$geometry: originGeo}}}) assert.eq(t.find({geo: {$geoNear: {$geometry: originGeo}}}).itcount(), 50); t.drop(); -t.ensureIndex({geo: "2dsphere"}); +t.createIndex({geo: "2dsphere"}); // Center point near the negative meridian originGeo = { @@ -270,7 +270,7 @@ assert.eq(t.find({geo: {$near: {$geometry: originGeo}}}).itcount(), 50); // Near search with points that are really far away. t.drop(); -t.ensureIndex({geo: "2dsphere"}); +t.createIndex({geo: "2dsphere"}); originGeo = { type: "Point", coordinates: [0.0, 0.0] diff --git a/jstests/core/geo_s2near_equator_opposite.js b/jstests/core/geo_s2near_equator_opposite.js index de196ea70eb..4b028baf43c 100644 --- a/jstests/core/geo_s2near_equator_opposite.js +++ b/jstests/core/geo_s2near_equator_opposite.js @@ -12,7 +12,7 @@ t.drop(); t.insert({loc: {type: 'Point', coordinates: [0, 0]}}); t.insert({loc: {type: 'Point', coordinates: [-1, 0]}}); -t.ensureIndex({loc: '2dsphere'}); +t.createIndex({loc: '2dsphere'}); // upper bound for half of earth's circumference in meters var dist = 40075000 / 2 + 1; diff --git a/jstests/core/geo_s2nearcorrect.js b/jstests/core/geo_s2nearcorrect.js index 54552a4bee5..80ece4223d2 100644 --- a/jstests/core/geo_s2nearcorrect.js +++ b/jstests/core/geo_s2nearcorrect.js @@ -10,7 +10,7 @@ longline = { "coordinates": [[0, 0], [179, 89]] }; t.insert({geo: longline}); -t.ensureIndex({geo: "2dsphere"}); +t.createIndex({geo: "2dsphere"}); origin = { "type": "Point", "coordinates": [45, 45] diff --git a/jstests/core/geo_s2nearwithin.js b/jstests/core/geo_s2nearwithin.js index 8018dfec575..eb334e89aff 100644 --- a/jstests/core/geo_s2nearwithin.js +++ b/jstests/core/geo_s2nearwithin.js @@ -18,7 +18,7 @@ origin = { "coordinates": [0, 0] }; -assert.commandWorked(t.ensureIndex({geo: "2dsphere"})); +assert.commandWorked(t.createIndex({geo: "2dsphere"})); // Near requires an index, and 2dsphere is an index. Spherical isn't // specified so this doesn't work. let res = assert.commandFailedWithCode(t.runCommand("aggregate", { diff --git a/jstests/core/geo_s2nongeoarray.js b/jstests/core/geo_s2nongeoarray.js index 4242a9f38e9..5fb5c59f1af 100644 --- a/jstests/core/geo_s2nongeoarray.js +++ b/jstests/core/geo_s2nongeoarray.js @@ -11,19 +11,19 @@ var data = {geo: oldPoint, nonGeo: [123, 456], otherNonGeo: [{b: [1, 2]}, {b: [3 t.drop(); assert.commandWorked(t.insert(data)); -assert.commandWorked(t.ensureIndex({otherNonGeo: 1})); +assert.commandWorked(t.createIndex({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()); t.drop(); t.insert(data); -t.ensureIndex({geo: "2d", nonGeo: 1, otherNonGeo: 1}); +t.createIndex({geo: "2d", nonGeo: 1, otherNonGeo: 1}); assert.eq(t.find({nonGeo: 123, geo: {$nearSphere: oldPoint}}).itcount(), 1); assert.eq(t.find({'otherNonGeo.b': 1, geo: {$nearSphere: oldPoint}}).itcount(), 1); t.drop(); t.insert(data); -t.ensureIndex({geo: "2dsphere", nonGeo: 1, otherNonGeo: 1}); +t.createIndex({geo: "2dsphere", nonGeo: 1, otherNonGeo: 1}); assert.eq(t.find({nonGeo: 123, geo: {$nearSphere: oldPoint}}).itcount(), 1); assert.eq(t.find({'otherNonGeo.b': 1, geo: {$nearSphere: oldPoint}}).itcount(), 1); diff --git a/jstests/core/geo_s2nonstring.js b/jstests/core/geo_s2nonstring.js index 960f0c727a8..a76a7cd073e 100644 --- a/jstests/core/geo_s2nonstring.js +++ b/jstests/core/geo_s2nonstring.js @@ -2,13 +2,13 @@ t = db.geo_s2nonstring; t.drop(); -t.ensureIndex({geo: '2dsphere', x: 1}); +t.createIndex({geo: '2dsphere', x: 1}); t.save({geo: {type: 'Point', coordinates: [0, 0]}, x: 'a'}); t.save({geo: {type: 'Point', coordinates: [0, 0]}, x: 5}); t.drop(); -t.ensureIndex({geo: '2dsphere', x: 1}); +t.createIndex({geo: '2dsphere', x: 1}); t.save({geo: {type: 'Point', coordinates: [0, 0]}, x: 'a'}); t.save({geo: {type: 'Point', coordinates: [0, 0]}}); diff --git a/jstests/core/geo_s2nopoints.js b/jstests/core/geo_s2nopoints.js index 0d2afdb1672..7b3a3b970a7 100644 --- a/jstests/core/geo_s2nopoints.js +++ b/jstests/core/geo_s2nopoints.js @@ -2,7 +2,7 @@ t = db.geo_s2nopoints; t.drop(); -t.ensureIndex({loc: "2dsphere", x: 1}); +t.createIndex({loc: "2dsphere", x: 1}); assert.eq( 0, t.count({loc: {$near: {$geometry: {type: 'Point', coordinates: [0, 0]}, $maxDistance: 10}}})); diff --git a/jstests/core/geo_s2oddshapes.js b/jstests/core/geo_s2oddshapes.js index 0cc60a661a4..9ebe6be7ed3 100644 --- a/jstests/core/geo_s2oddshapes.js +++ b/jstests/core/geo_s2oddshapes.js @@ -6,7 +6,7 @@ // ] var t = db.geo_s2oddshapes; t.drop(); -t.ensureIndex({geo: "2dsphere"}); +t.createIndex({geo: "2dsphere"}); var testPoint = {name: "origin", geo: {type: "Point", coordinates: [0.0, 0.0]}}; @@ -58,7 +58,7 @@ assert.eq(result.itcount(), 3); // Test a poly that is the size of half the earth. t.drop(); -t.ensureIndex({geo: "2dsphere"}); +t.createIndex({geo: "2dsphere"}); var insidePoint = {name: "inside", geo: {type: "Point", name: "inside", coordinates: [100.0, 0.0]}}; @@ -84,7 +84,7 @@ assert.eq(point.name, 'inside'); // Test a poly that is very small. A couple meters around. t.drop(); -t.ensureIndex({geo: "2dsphere"}); +t.createIndex({geo: "2dsphere"}); insidePoint = { name: "inside", diff --git a/jstests/core/geo_s2ordering.js b/jstests/core/geo_s2ordering.js index 8ef84905b75..9e53cafb981 100644 --- a/jstests/core/geo_s2ordering.js +++ b/jstests/core/geo_s2ordering.js @@ -35,7 +35,7 @@ function makepoints(needle) { } function runTest(index) { - assert.commandWorked(coll.ensureIndex(index)); + assert.commandWorked(coll.createIndex(index)); const cursor = coll.find({nongeo: needle, geo: {$within: {$centerSphere: [[0, 0], Math.PI / 180.0]}}}); const stats = cursor.explain("executionStats").executionStats; diff --git a/jstests/core/geo_s2overlappingpolys.js b/jstests/core/geo_s2overlappingpolys.js index 9dd7125349a..3cc1f254a37 100644 --- a/jstests/core/geo_s2overlappingpolys.js +++ b/jstests/core/geo_s2overlappingpolys.js @@ -6,7 +6,7 @@ var t = db.geo_s2overlappingpolys; t.drop(); -t.ensureIndex({geo: "2dsphere"}); +t.createIndex({geo: "2dsphere"}); var minError = 0.8e-13; diff --git a/jstests/core/geo_s2polywithholes.js b/jstests/core/geo_s2polywithholes.js index c20da5a34aa..e37606465f6 100644 --- a/jstests/core/geo_s2polywithholes.js +++ b/jstests/core/geo_s2polywithholes.js @@ -5,7 +5,7 @@ */ var t = db.geo_s2weirdpolys; t.drop(); -t.ensureIndex({geo: "2dsphere"}); +t.createIndex({geo: "2dsphere"}); var centerPoint = {"type": "Point", "coordinates": [0.5, 0.5]}; var edgePoint = {"type": "Point", "coordinates": [0, 0.5]}; diff --git a/jstests/core/geo_s2selfintersectingpoly.js b/jstests/core/geo_s2selfintersectingpoly.js index 0887f850fe3..0ac522fa6f7 100644 --- a/jstests/core/geo_s2selfintersectingpoly.js +++ b/jstests/core/geo_s2selfintersectingpoly.js @@ -1,6 +1,6 @@ var t = db.geo_s2selfintersectingpoly; t.drop(); -t.ensureIndex({geo: "2dsphere"}); +t.createIndex({geo: "2dsphere"}); var intersectingPolygon = { "type": "Polygon", diff --git a/jstests/core/geo_s2sparse.js b/jstests/core/geo_s2sparse.js index d058afb9f9b..1a9a3b67b9b 100644 --- a/jstests/core/geo_s2sparse.js +++ b/jstests/core/geo_s2sparse.js @@ -15,7 +15,7 @@ var indexName = 'geo_2dsphere_nonGeo_1'; // Clean up. coll.drop(); -coll.ensureIndex(indexSpec); +coll.createIndex(indexSpec); var bulkInsertDocs = function(coll, numDocs, makeDocFn) { print("Bulk inserting " + numDocs + " documents"); @@ -77,7 +77,7 @@ assert.eq(N + N, coll.validate().keysPerIndex[indexName]); // coll.drop(); -coll.ensureIndex(indexSpec, {"2dsphereIndexVersion": 1}); +coll.createIndex(indexSpec, {"2dsphereIndexVersion": 1}); // Insert N documents with the geo field. bulkInsertDocs(coll, N, function(i) { @@ -101,7 +101,7 @@ assert.eq(N + N, coll.validate().keysPerIndex[indexName]); // Clean up. coll.drop(); -coll.ensureIndex({geo: "2dsphere", otherGeo: "2dsphere"}); +coll.createIndex({geo: "2dsphere", otherGeo: "2dsphere"}); indexName = 'geo_2dsphere_otherGeo_2dsphere'; diff --git a/jstests/core/geo_s2twofields.js b/jstests/core/geo_s2twofields.js index 73666f2bf5e..160b5f513e1 100644 --- a/jstests/core/geo_s2twofields.js +++ b/jstests/core/geo_s2twofields.js @@ -55,7 +55,7 @@ function timeWithoutAndWithAnIndex(index, query) { var withoutTime = semiRigorousTime(function() { return t.find(query).explain("executionStats").executionStats.executionTimeMillis; }); - t.ensureIndex(index); + t.createIndex(index); var withTime = semiRigorousTime(function() { return t.find(query).explain("executionStats").executionStats.executionTimeMillis; }); diff --git a/jstests/core/geo_s2validindex.js b/jstests/core/geo_s2validindex.js index 4c024d2d585..444346def14 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.commandWorked(coll.ensureIndex({geo: "2dsphere", other: 1})); +assert.commandWorked(coll.createIndex({geo: "2dsphere", other: 1})); // Valid index coll.drop(); -assert.commandWorked(coll.ensureIndex({geo: "2dsphere", other: 1, geo2: "2dsphere"})); +assert.commandWorked(coll.createIndex({geo: "2dsphere", other: 1, geo2: "2dsphere"})); // Invalid index, using hash with 2dsphere coll.drop(); -assert.commandFailed(coll.ensureIndex({geo: "2dsphere", other: "hash"})); +assert.commandFailed(coll.createIndex({geo: "2dsphere", other: "hash"})); // Invalid index, using 2d with 2dsphere coll.drop(); -assert.commandFailed(coll.ensureIndex({geo: "2dsphere", other: "2d"})); +assert.commandFailed(coll.createIndex({geo: "2dsphere", other: "2d"})); jsTest.log("Success!"); diff --git a/jstests/core/geo_s2within.js b/jstests/core/geo_s2within.js index c32eb4fd612..4f908a4f303 100644 --- a/jstests/core/geo_s2within.js +++ b/jstests/core/geo_s2within.js @@ -4,7 +4,7 @@ // ] t = db.geo_s2within; t.drop(); -t.ensureIndex({geo: "2dsphere"}); +t.createIndex({geo: "2dsphere"}); somepoly = { "type": "Polygon", @@ -19,7 +19,7 @@ res = t.find({"geo": {"$within": {"$geometry": somepoly}}}); assert.eq(res.itcount(), 1); t.drop(); -t.ensureIndex({geo: "2dsphere"}); +t.createIndex({geo: "2dsphere"}); somepoly = { "type": "Polygon", "coordinates": [ diff --git a/jstests/core/geo_small_large.js b/jstests/core/geo_small_large.js index 5cfa3e68e0f..94d5298081e 100644 --- a/jstests/core/geo_small_large.js +++ b/jstests/core/geo_small_large.js @@ -56,7 +56,7 @@ for (var i = 0; i < scales.length; i++) { var t = db["geo_small_large"]; t.drop(); - t.ensureIndex({p: "2d"}, {min: min, max: max, bits: bits}); + t.createIndex({p: "2d"}, {min: min, max: max, bits: bits}); var outPoints = 0; var inPoints = 0; diff --git a/jstests/core/geo_sort1.js b/jstests/core/geo_sort1.js index 22e185d0106..3e9ee494812 100644 --- a/jstests/core/geo_sort1.js +++ b/jstests/core/geo_sort1.js @@ -12,7 +12,7 @@ for (x = 0; x < 10; x++) { } } -t.ensureIndex({loc: "2d", foo: 1}); +t.createIndex({loc: "2d", foo: 1}); q = t.find({loc: {$near: [5, 5]}, foo: {$gt: 20}}); m = function(z) { diff --git a/jstests/core/geo_uniqueDocs.js b/jstests/core/geo_uniqueDocs.js index 88162e42498..b6eaf4e0501 100644 --- a/jstests/core/geo_uniqueDocs.js +++ b/jstests/core/geo_uniqueDocs.js @@ -11,7 +11,7 @@ t.drop(); assert.commandWorked(t.save({locs: [[0, 2], [3, 4]]})); assert.commandWorked(t.save({locs: [[6, 8], [10, 10]]})); -assert.commandWorked(t.ensureIndex({locs: '2d'})); +assert.commandWorked(t.createIndex({locs: '2d'})); // $geoNear tests // uniqueDocs option is ignored. diff --git a/jstests/core/geo_uniqueDocs2.js b/jstests/core/geo_uniqueDocs2.js index 9e0b4a0a284..1486023b73f 100644 --- a/jstests/core/geo_uniqueDocs2.js +++ b/jstests/core/geo_uniqueDocs2.js @@ -12,7 +12,7 @@ t = db[collName]; t.drop(); t.save({loc: [[20, 30], [40, 50]]}); -t.ensureIndex({loc: '2d'}); +t.createIndex({loc: '2d'}); // Check exact matches of different locations. assert.eq(1, t.count({loc: [20, 30]})); @@ -109,5 +109,5 @@ for (i = 0; i < 10000; ++i) { } arr.push([100, 100]); t.save({loc: arr}); -t.ensureIndex({loc: '2d'}); +t.createIndex({loc: '2d'}); assert.eq(1, t.count({loc: {$within: {$center: [[99, 99], 5]}}})); diff --git a/jstests/core/geo_update.js b/jstests/core/geo_update.js index 21cf42d2208..015e56e34a5 100644 --- a/jstests/core/geo_update.js +++ b/jstests/core/geo_update.js @@ -11,7 +11,7 @@ var coll = db.testGeoUpdate; coll.drop(); -coll.ensureIndex({loc: "2d"}); +coll.createIndex({loc: "2d"}); // Test normal update print("Updating..."); diff --git a/jstests/core/geo_update1.js b/jstests/core/geo_update1.js index a4de04fbd93..cd23e65b7b7 100644 --- a/jstests/core/geo_update1.js +++ b/jstests/core/geo_update1.js @@ -11,7 +11,7 @@ for (var x = 0; x < 10; x++) { } } -t.ensureIndex({loc: "2d"}); +t.createIndex({loc: "2d"}); function p() { print("--------------"); diff --git a/jstests/core/geo_update2.js b/jstests/core/geo_update2.js index f1b94925cb7..d67b3a9bcc1 100644 --- a/jstests/core/geo_update2.js +++ b/jstests/core/geo_update2.js @@ -11,7 +11,7 @@ for (var x = 0; x < 10; x++) { } } -t.ensureIndex({loc: "2d"}); +t.createIndex({loc: "2d"}); function p() { print("--------------"); diff --git a/jstests/core/geo_update_btree.js b/jstests/core/geo_update_btree.js index 8cf711a9e48..7a58362fe18 100644 --- a/jstests/core/geo_update_btree.js +++ b/jstests/core/geo_update_btree.js @@ -10,7 +10,7 @@ var coll = db.getCollection("jstests_geo_update_btree"); coll.drop(); -coll.ensureIndex({loc: '2d'}); +coll.createIndex({loc: '2d'}); var big = new Array(3000).toString(); diff --git a/jstests/core/geo_update_btree2.js b/jstests/core/geo_update_btree2.js index 3bc0a7c9760..e37dbb190e1 100644 --- a/jstests/core/geo_update_btree2.js +++ b/jstests/core/geo_update_btree2.js @@ -28,7 +28,7 @@ var status = function(msg) { var coll = db.getCollection("jstests_geo_update_btree2"); coll.drop(); -coll.ensureIndex({loc: '2d'}); +coll.createIndex({loc: '2d'}); status("Inserting points..."); diff --git a/jstests/core/geo_update_dedup.js b/jstests/core/geo_update_dedup.js index 34e9aff30dd..3938204c70e 100644 --- a/jstests/core/geo_update_dedup.js +++ b/jstests/core/geo_update_dedup.js @@ -13,7 +13,7 @@ var t = db.jstests_geo_update_dedup; // 2d index with $near t.drop(); -t.ensureIndex({locs: "2d"}); +t.createIndex({locs: "2d"}); t.save({locs: [[49.999, 49.999], [50.0, 50.0], [50.001, 50.001]]}); var q = {locs: {$near: [50.0, 50.0]}}; @@ -24,7 +24,7 @@ assert.eq(1, res.nMatched); assert.eq(1, t.findOne().touchCount); t.drop(); -t.ensureIndex({locs: "2d"}); +t.createIndex({locs: "2d"}); t.save({locs: [{x: 49.999, y: 49.999}, {x: 50.0, y: 50.0}, {x: 50.001, y: 50.001}]}); res = t.update({locs: {$near: {x: 50.0, y: 50.0}}}, {$inc: {touchCount: 1}}); assert.eq(1, res.nMatched); @@ -32,7 +32,7 @@ assert.eq(1, t.findOne().touchCount); // 2d index with $within t.drop(); -t.ensureIndex({loc: "2d"}); +t.createIndex({loc: "2d"}); t.save({loc: [[0, 0], [1, 1]]}); res = t.update({loc: {$within: {$center: [[0, 0], 2]}}}, {$inc: {touchCount: 1}}, false, true); @@ -41,7 +41,7 @@ assert.eq(1, t.findOne().touchCount); // 2dsphere index with $geoNear t.drop(); -t.ensureIndex({geo: "2dsphere"}); +t.createIndex({geo: "2dsphere"}); var x = { "type": "Polygon", "coordinates": [[[49.999, 49.999], [50.0, 50.0], [50.001, 50.001], [49.999, 49.999]]] @@ -62,7 +62,7 @@ var locdata = [ {geo: {type: "Point", coordinates: [50.001, 50.001]}} ]; t.save({locdata: locdata, count: 0}); -t.ensureIndex({"locdata.geo": "2dsphere"}); +t.createIndex({"locdata.geo": "2dsphere"}); res = t.update({"locdata.geo": {$geoNear: {"type": "Point", "coordinates": [50.0, 50.0]}}}, {$inc: {touchCount: 1}}, diff --git a/jstests/core/geo_validate.js b/jstests/core/geo_validate.js index cd839ef8f97..0518740c02e 100644 --- a/jstests/core/geo_validate.js +++ b/jstests/core/geo_validate.js @@ -8,7 +8,7 @@ var coll = db.geo_validate; coll.drop(); -coll.ensureIndex({geo: "2dsphere"}); +coll.createIndex({geo: "2dsphere"}); // // diff --git a/jstests/core/geoa.js b/jstests/core/geoa.js index c1e0a2f796a..52a9d79db3b 100644 --- a/jstests/core/geoa.js +++ b/jstests/core/geoa.js @@ -10,7 +10,7 @@ t.save({_id: 1, a: {loc: [5, 5]}}); t.save({_id: 2, a: {loc: [6, 6]}}); t.save({_id: 3, a: {loc: [7, 7]}}); -t.ensureIndex({"a.loc": "2d"}); +t.createIndex({"a.loc": "2d"}); cur = t.find({"a.loc": {$near: [6, 6]}}); assert.eq(2, cur.next()._id, "A1"); diff --git a/jstests/core/geob.js b/jstests/core/geob.js index 6a7839253ee..b1093172618 100644 --- a/jstests/core/geob.js +++ b/jstests/core/geob.js @@ -17,7 +17,7 @@ t.save(a); t.save(b); t.save(c); t.save(d); -t.ensureIndex({p: "2d"}); +t.createIndex({p: "2d"}); let res = t.aggregate({$geoNear: {near: [0, 0], distanceField: "dis"}}).toArray(); diff --git a/jstests/core/geoc.js b/jstests/core/geoc.js index 4264b6f9295..2c0948582c7 100644 --- a/jstests/core/geoc.js +++ b/jstests/core/geoc.js @@ -15,7 +15,7 @@ for (var i = 0; i < N; i++) for (var i = 0; i < N; i++) t.insert({loc: [-100 + Math.random(), -100 + Math.random()], z: 2}); -t.ensureIndex({loc: '2d'}); +t.createIndex({loc: '2d'}); function test(z, l) { assert.lt( diff --git a/jstests/core/geod.js b/jstests/core/geod.js index fc6c37f1da3..47b067809f8 100644 --- a/jstests/core/geod.js +++ b/jstests/core/geod.js @@ -2,7 +2,7 @@ var t = db.geod; t.drop(); t.save({loc: [0, 0]}); t.save({loc: [0.5, 0]}); -t.ensureIndex({loc: "2d"}); +t.createIndex({loc: "2d"}); // do a few geoNears with different maxDistances. The first iteration // should match no points in the dataset. // @tags: [ diff --git a/jstests/core/geoe.js b/jstests/core/geoe.js index 9568e13dc08..84bc34f7a74 100644 --- a/jstests/core/geoe.js +++ b/jstests/core/geoe.js @@ -22,7 +22,7 @@ t.insert({"_id": 12, "geo": [-122.3, 37.66]}); t.insert({"_id": 13, "geo": [-122.2435, 37.637072]}); t.insert({"_id": 14, "geo": [-122.289505, 37.695774]}); -t.ensureIndex({geo: "2d"}); +t.createIndex({geo: "2d"}); c = t.find({geo: {"$within": {"$box": [[-125.078461, 36.494473], [-120.320648, 38.905199]]}}}); assert.eq(11, c.count(), "A1"); diff --git a/jstests/core/geof.js b/jstests/core/geof.js index ad15037db3b..31e5439b158 100644 --- a/jstests/core/geof.js +++ b/jstests/core/geof.js @@ -14,7 +14,7 @@ t.insert({loc: [-0.7, -0.7]}); t.insert({loc: [-0.9, 0]}); t.insert({loc: [-0.9, 0]}); -t.ensureIndex({loc: "2d"}); +t.createIndex({loc: "2d"}); t.find({loc: {$near: [0, 0]}}).limit(2).forEach(function(o) { // printjson(o); diff --git a/jstests/core/geonear_cmd_input_validation.js b/jstests/core/geonear_cmd_input_validation.js index 2c3116c3a6d..04f5e73fed0 100644 --- a/jstests/core/geonear_cmd_input_validation.js +++ b/jstests/core/geonear_cmd_input_validation.js @@ -6,7 +6,7 @@ // ] var t = db.geonear_cmd_input_validation; t.drop(); -t.ensureIndex({loc: "2dsphere"}); +t.createIndex({loc: "2dsphere"}); // The test matrix. Some combinations are not supported: // 2d index and GeoJSON. diff --git a/jstests/core/getmore_invalidated_documents.js b/jstests/core/getmore_invalidated_documents.js index 3bc5458072e..4fc66fca5c8 100644 --- a/jstests/core/getmore_invalidated_documents.js +++ b/jstests/core/getmore_invalidated_documents.js @@ -23,7 +23,7 @@ var y; // Case #1: Text search with deletion invalidation. t.drop(); -assert.commandWorked(t.ensureIndex({a: "text"})); +assert.commandWorked(t.createIndex({a: "text"})); assert.commandWorked(t.insert({_id: 1, a: "bar"})); assert.commandWorked(t.insert({_id: 2, a: "bar"})); assert.commandWorked(t.insert({_id: 3, a: "bar"})); @@ -41,7 +41,7 @@ assert(count === 0 || count === 1); // Case #2: Text search with mutation invalidation. t.drop(); -assert.commandWorked(t.ensureIndex({a: "text"})); +assert.commandWorked(t.createIndex({a: "text"})); assert.commandWorked(t.insert({_id: 1, a: "bar"})); assert.commandWorked(t.insert({_id: 2, a: "bar"})); assert.commandWorked(t.insert({_id: 3, a: "bar"})); @@ -60,7 +60,7 @@ assert(!cursor.hasNext() || cursor.next()["a"] === "bar"); // Case #3: Merge sort with deletion invalidation. t.drop(); -assert.commandWorked(t.ensureIndex({a: 1, b: 1})); +assert.commandWorked(t.createIndex({a: 1, b: 1})); assert.commandWorked(t.insert({a: 1, b: 1})); assert.commandWorked(t.insert({a: 1, b: 2})); assert.commandWorked(t.insert({a: 2, b: 3})); @@ -77,7 +77,7 @@ assert(count === 1 || count === 2); // Case #4: Merge sort with mutation invalidation. t.drop(); -assert.commandWorked(t.ensureIndex({a: 1, b: 1})); +assert.commandWorked(t.createIndex({a: 1, b: 1})); assert.commandWorked(t.insert({a: 1, b: 1})); assert.commandWorked(t.insert({a: 1, b: 2})); assert.commandWorked(t.insert({a: 2, b: 3})); @@ -101,7 +101,7 @@ assert(!cursor.hasNext()); // Case #5: 2d near with deletion invalidation. t.drop(); -t.ensureIndex({geo: "2d"}); +t.createIndex({geo: "2d"}); for (x = -1; x < 1; x++) { for (y = -1; y < 1; y++) { assert.commandWorked(t.insert({geo: [x, y]})); @@ -121,7 +121,7 @@ assert(cursor.hasNext()); // Case #6: 2dsphere near with deletion invalidation. t.drop(); -t.ensureIndex({geo: "2dsphere"}); +t.createIndex({geo: "2dsphere"}); for (x = -1; x < 1; x++) { for (y = -1; y < 1; y++) { assert.commandWorked(t.insert({geo: [x, y]})); @@ -141,7 +141,7 @@ assert(cursor.hasNext()); // Case #7: 2dsphere near with deletion invalidation (again). t.drop(); -t.ensureIndex({geo: "2dsphere"}); +t.createIndex({geo: "2dsphere"}); for (x = 0; x < 6; x++) { assert.commandWorked(t.insert({geo: [x, x]})); } @@ -159,7 +159,7 @@ assert.gte(cursor.itcount(), 0); // Case #8: 2d near with mutation invalidation. t.drop(); -t.ensureIndex({geo: "2d"}); +t.createIndex({geo: "2d"}); for (x = -1; x < 1; x++) { for (y = -1; y < 1; y++) { assert.commandWorked(t.insert({geo: [x, y]})); @@ -182,7 +182,7 @@ assert(nextDoc.geo[0] === 0 || nextDoc.geo[1] === 0); // Case #9: 2dsphere near with mutation invalidation. t.drop(); -t.ensureIndex({geo: "2dsphere"}); +t.createIndex({geo: "2dsphere"}); for (x = -1; x < 1; x++) { for (y = -1; y < 1; y++) { assert.commandWorked(t.insert({geo: [x, y]})); @@ -205,7 +205,7 @@ assert(nextDoc.geo[0] === 0 || nextDoc.geo[1] === 0); // Case #10: sort with deletion invalidation. t.drop(); -t.ensureIndex({a: 1}); +t.createIndex({a: 1}); t.insert({a: 1, b: 2}); t.insert({a: 3, b: 3}); t.insert({a: 2, b: 1}); @@ -222,7 +222,7 @@ if (cursor.hasNext()) { // Case #11: sort with mutation invalidation. t.drop(); -t.ensureIndex({a: 1}); +t.createIndex({a: 1}); t.insert({a: 1, b: 2}); t.insert({a: 3, b: 3}); t.insert({a: 2, b: 1}); diff --git a/jstests/core/hint1.js b/jstests/core/hint1.js index 6542f9752bc..d584144e641 100644 --- a/jstests/core/hint1.js +++ b/jstests/core/hint1.js @@ -2,7 +2,7 @@ p = db.jstests_hint1; p.drop(); p.save({ts: new Date(1), cls: "entry", verticals: "alleyinsider", live: true}); -p.ensureIndex({ts: 1}); +p.createIndex({ts: 1}); assert.eq( 1, diff --git a/jstests/core/idhack.js b/jstests/core/idhack.js index a884fecd920..83a359f0f53 100644 --- a/jstests/core/idhack.js +++ b/jstests/core/idhack.js @@ -41,7 +41,7 @@ assert.eq(1, explain.executionStats.totalKeysExamined); assert(isIdhack(db, explain.queryPlanner.winningPlan)); // ID hack cannot be used with hint(). -t.ensureIndex({_id: 1, a: 1}); +t.createIndex({_id: 1, a: 1}); explain = t.find(query).hint({_id: 1, a: 1}).explain(); assert(!isIdhack(db, explain.queryPlanner.winningPlan)); diff --git a/jstests/core/in.js b/jstests/core/in.js index 852f6bcbca4..ca8cd77b189 100644 --- a/jstests/core/in.js +++ b/jstests/core/in.js @@ -17,7 +17,7 @@ assert.eq(1, t.find({a: {$in: [1]}}).itcount(), "A"); assert.eq(1, t.find({a: {$in: [2]}}).itcount(), "B"); assert.eq(2, t.find({a: {$in: [1, 2]}}).itcount(), "C"); -t.ensureIndex({a: 1}); +t.createIndex({a: 1}); assert.eq(1, t.find({a: {$in: [1]}}).itcount(), "D"); assert.eq(1, t.find({a: {$in: [2]}}).itcount(), "E"); diff --git a/jstests/core/in2.js b/jstests/core/in2.js index ddcee67ccd0..6682bbc79c1 100644 --- a/jstests/core/in2.js +++ b/jstests/core/in2.js @@ -17,7 +17,7 @@ function go(name, index) { t.save({a: 3, b: 1}); if (index) - t.ensureIndex(index); + t.createIndex(index); assert.eq(7, t.find({a: {$in: [1, 2]}}).count(), name + " A"); diff --git a/jstests/core/in3.js b/jstests/core/in3.js index 02680642939..bd64329ded4 100644 --- a/jstests/core/in3.js +++ b/jstests/core/in3.js @@ -19,5 +19,5 @@ function doTest() { } doTest(); -t.ensureIndex({key: 1}); +t.createIndex({key: 1}); doTest(); diff --git a/jstests/core/in4.js b/jstests/core/in4.js index df9eea2577b..e916ca7c82d 100644 --- a/jstests/core/in4.js +++ b/jstests/core/in4.js @@ -33,5 +33,5 @@ function doTest() { doTest(); // SERVER-1943 not fixed yet -t.ensureIndex({key: 1}); +t.createIndex({key: 1}); doTest(); diff --git a/jstests/core/in5.js b/jstests/core/in5.js index 2f92b057d6c..80f37e6b473 100644 --- a/jstests/core/in5.js +++ b/jstests/core/in5.js @@ -27,7 +27,7 @@ function go(fn) { i = {}; i[fn] = 1; - t.ensureIndex(i); + t.createIndex(i); assert.eq(1, t.find(x).itcount(), "B1 - " + fn); assert.eq(1, t.find(y).itcount(), "B2 - " + fn); @@ -39,7 +39,7 @@ function go(fn) { i = {}; i[fn + ".a"] = 1; - t.ensureIndex(i); + t.createIndex(i); assert.eq(2, t.getIndexes().length, "T3"); assert.eq(1, t.find(x).itcount(), "C1 - " + fn); diff --git a/jstests/core/in6.js b/jstests/core/in6.js index 4ee06541b81..ab8322cfe0a 100644 --- a/jstests/core/in6.js +++ b/jstests/core/in6.js @@ -9,5 +9,5 @@ function doTest() { } doTest(); -t.ensureIndex({i: 1}); +t.createIndex({i: 1}); doTest(); diff --git a/jstests/core/in8.js b/jstests/core/in8.js index a6bdc520926..f1b6188347c 100644 --- a/jstests/core/in8.js +++ b/jstests/core/in8.js @@ -8,7 +8,7 @@ function checkResults(query) { assert.eq(4, t.find(query).itcount()); } -t.ensureIndex({x: 1}); +t.createIndex({x: 1}); t.save({x: 'aa'}); t.save({x: 'ab'}); t.save({x: 'ac'}); diff --git a/jstests/core/inc1.js b/jstests/core/inc1.js index 50a7892e5a4..551d15e0f63 100644 --- a/jstests/core/inc1.js +++ b/jstests/core/inc1.js @@ -26,7 +26,7 @@ test(5, "E"); t.update({_id: 1}, {$inc: {x: -1}}); test(4, "F"); -t.ensureIndex({x: 1}); +t.createIndex({x: 1}); t.update({_id: 1}, {$inc: {x: 1}}); test(5, "G"); diff --git a/jstests/core/inc2.js b/jstests/core/inc2.js index 6ff4842e254..debdfde82cb 100644 --- a/jstests/core/inc2.js +++ b/jstests/core/inc2.js @@ -17,7 +17,7 @@ assert.eq("1,2,3", order(), "A"); t.update({_id: 1}, {$inc: {x: 4}}); assert.eq("2,3,1", order(), "B"); -t.ensureIndex({x: 1}); +t.createIndex({x: 1}); assert.eq("2,3,1", order(), "C"); t.update({_id: 3}, {$inc: {x: 4}}); diff --git a/jstests/core/index1.js b/jstests/core/index1.js index 2efb9d22189..4c06bfe03fd 100644 --- a/jstests/core/index1.js +++ b/jstests/core/index1.js @@ -13,7 +13,7 @@ t.save(o); assert(t.findOne().z.a == 17); assert(t.findOne({z: {a: 17}}) == null); -t.ensureIndex({"z.a": 1}); +t.createIndex({"z.a": 1}); assert(t.findOne().z.a == 17); assert(t.findOne({z: {a: 17}}) == null); diff --git a/jstests/core/index13.js b/jstests/core/index13.js index 9979116ae51..97a3a85f773 100644 --- a/jstests/core/index13.js +++ b/jstests/core/index13.js @@ -40,7 +40,7 @@ index = { 'a.b': 1, 'a.c': 1 }; -t.ensureIndex(index); +t.createIndex(index); t.save({a: [{b: 1}, {c: 1}]}); t.save({a: [{b: 1, c: 1}]}); assert.eq(2, t.count()); @@ -68,7 +68,7 @@ index = { 'd.e': 1, 'd.f': 1 }; -t.ensureIndex(index); +t.createIndex(index); t.insert({a: [{b: 1}, {c: 1}], d: {e: 1, f: 1}}); t.insert({a: [{b: 1, c: 1}], d: {e: 1, f: 1}}); t.insert({a: {b: 1, c: 1}, d: [{e: 1, f: 1}]}); @@ -89,7 +89,7 @@ index = { 'a.b.c': 1, 'a.b.d': 1 }; -t.ensureIndex(index); +t.createIndex(index); t.insert({a: [{b: [{c: 1, d: 1}]}]}); t.insert({a: [{b: [{c: 1}, {d: 1}]}]}); assert.eq(2, t.count()); @@ -104,7 +104,7 @@ index = { 'a.b.x': 1, 'a.b.y': 1 }; -t.ensureIndex(index); +t.createIndex(index); t.save({a: {b: {x: 1, y: 1}}}); t.save({a: [{b: {x: 1}}, {b: {y: 1}}]}); t.save({a: [{b: [{x: 1}, {y: 1}]}]}); @@ -125,7 +125,7 @@ index = { 'a.b.x': 1, 'a.b.y': 1 }; -t.ensureIndex(index); +t.createIndex(index); // With $ne. assertResults({a: {$ne: 4}, 'a.b': {$elemMatch: {x: 1, y: 1}}}); @@ -141,7 +141,7 @@ index = { 'a.b.d': 1, 'a.e.g': 1 }; -t.ensureIndex(index); +t.createIndex(index); t.save({a: {b: {c: 1, d: 1}, e: {f: 1, g: 1}}}); t.save({a: [{b: {c: 1}, e: {f: 1}}, {b: {d: 1}, e: {g: 1}}]}); t.save({a: [{b: {c: 1}}, {e: {f: 1}}, {b: {d: 1}}, {e: {g: 1}}]}); @@ -166,7 +166,7 @@ index = { 'a.b.d': 1, 'a.e.d': 1 }; -t.ensureIndex(index); +t.createIndex(index); t.save({a: [{b: [{c: 1, d: 1}]}, {e: [{c: 1, d: 1}]}]}); assert.eq(1, t.count()); diff --git a/jstests/core/index2.js b/jstests/core/index2.js index 098bdc20529..2c37c48c871 100644 --- a/jstests/core/index2.js +++ b/jstests/core/index2.js @@ -40,7 +40,7 @@ assert(t.findOne({z: {a: 17}}).z.a == 17); assert(t.find({z: {a: 17}}).length() == 2); assert(t.find({z: {a: 18}}).length() == 1); -t.ensureIndex({z: 1}); +t.createIndex({z: 1}); assert(t.findOne({z: {a: 17}}).z.a == 17); assert(t.find({z: {a: 17}}).length() == 2); diff --git a/jstests/core/index3.js b/jstests/core/index3.js index 6ae7c4b82dd..cc5ad3b0796 100644 --- a/jstests/core/index3.js +++ b/jstests/core/index3.js @@ -7,11 +7,11 @@ t.drop(); assert(t.getIndexes().length == 0); -t.ensureIndex({name: 1}); +t.createIndex({name: 1}); t.save({name: "a"}); -t.ensureIndex({name: 1}); +t.createIndex({name: 1}); assert(t.getIndexes().length == 2); diff --git a/jstests/core/index4.js b/jstests/core/index4.js index 37ebce75a9c..179bcdd9726 100644 --- a/jstests/core/index4.js +++ b/jstests/core/index4.js @@ -14,10 +14,10 @@ t.save({name: "alleyinsider", instances: [{pool: "prod1"}, {pool: "dev1"}]}); t.save({name: "clusterstock", instances: [{pool: "dev1"}]}); // this should fail, not allowed -- we confirm that. -t.ensureIndex({instances: {pool: 1}}); +t.createIndex({instances: {pool: 1}}); assert.eq(1, t.getIndexes().length, "no indexes other than _id should be here yet"); -t.ensureIndex({"instances.pool": 1}); +t.createIndex({"instances.pool": 1}); sleep(10); diff --git a/jstests/core/index5.js b/jstests/core/index5.js index f46654c6602..908b433c299 100644 --- a/jstests/core/index5.js +++ b/jstests/core/index5.js @@ -22,5 +22,5 @@ t.save({a: 2}); validate(); -t.ensureIndex({a: -1}); +t.createIndex({a: -1}); validate(); diff --git a/jstests/core/index6.js b/jstests/core/index6.js index 9adef9bf366..4626e9359ea 100644 --- a/jstests/core/index6.js +++ b/jstests/core/index6.js @@ -4,5 +4,5 @@ r = db.ed.db.index6; r.drop(); r.save({comments: [{name: "eliot", foo: 1}]}); -r.ensureIndex({"comments.name": 1}); +r.createIndex({"comments.name": 1}); assert(r.findOne({"comments.name": "eliot"})); diff --git a/jstests/core/index8.js b/jstests/core/index8.js index 5bae0bc6de2..55ba8b805c9 100644 --- a/jstests/core/index8.js +++ b/jstests/core/index8.js @@ -8,9 +8,9 @@ t = db.jstests_index8; t.drop(); -t.ensureIndex({a: 1}); -t.ensureIndex({b: 1}, true); -t.ensureIndex({c: 1}, [false, "cIndex"]); +t.createIndex({a: 1}); +t.createIndex({b: 1}, true); +t.createIndex({c: 1}, [false, "cIndex"]); checkIndexes = function(num) { const indexes = t.getIndexes(); @@ -47,7 +47,7 @@ assert.eq(3, t.find().hint({b: 1}).toArray().length); assert.eq(3, t.find().hint({a: 1}).toArray().length); t.drop(); -t.ensureIndex({a: 1, b: -1}, true); +t.createIndex({a: 1, b: -1}, true); t.save({a: 2, b: 3}); t.save({a: 2, b: 3}); t.save({a: 2, b: 4}); @@ -55,13 +55,13 @@ t.save({a: 1, b: 3}); assert.eq(3, t.find().count()); t.drop(); -t.ensureIndex({a: 1}, true); +t.createIndex({a: 1}, true); t.save({a: [2, 3]}); t.save({a: 2}); assert.eq(1, t.find().count()); t.drop(); -t.ensureIndex({a: 1}, true); +t.createIndex({a: 1}, true); t.save({a: 2}); t.save({a: [1, 2, 3]}); t.save({a: [3, 2, 1]}); diff --git a/jstests/core/index_arr1.js b/jstests/core/index_arr1.js index cc6f1683bd1..d6db3e621cd 100644 --- a/jstests/core/index_arr1.js +++ b/jstests/core/index_arr1.js @@ -11,11 +11,11 @@ t.insert({_id: 3, a: 5}); assert.eq(3, t.find({a: 5}).itcount(), "A1"); -t.ensureIndex({a: 1, "b.x": 1}); +t.createIndex({a: 1, "b.x": 1}); assert.eq(3, t.find({a: 5}).itcount(), "A2"); // SERVER-1082 assert.eq(2, t.getIndexes().length, "B1"); t.insert({_id: 4, a: 5, b: []}); -t.ensureIndex({a: 1, "b.a": 1, "b.c": 1}); +t.createIndex({a: 1, "b.a": 1, "b.c": 1}); assert.eq(3, t.getIndexes().length, "B2"); diff --git a/jstests/core/index_arr2.js b/jstests/core/index_arr2.js index cd0df2533d3..faca8be6337 100644 --- a/jstests/core/index_arr2.js +++ b/jstests/core/index_arr2.js @@ -24,9 +24,9 @@ function test(withIndex) { Z = t.find(query).count(); if (withIndex) { - // t.ensureIndex( { 'a.b.c' : 1, 'created' : -1 } ) - // t.ensureIndex( { created : -1 } ) - t.ensureIndex({'a.b.c': 1}, {name: "x"}); + // t.createIndex( { 'a.b.c' : 1, 'created' : -1 } ) + // t.createIndex( { created : -1 } ) + t.createIndex({'a.b.c': 1}, {name: "x"}); } var res = t.update(query, {'$set': {"a.0.b.c": 0}}, false, true); diff --git a/jstests/core/index_bounds_number_edge_cases.js b/jstests/core/index_bounds_number_edge_cases.js index 0ab482028ed..3da4e53e2d0 100644 --- a/jstests/core/index_bounds_number_edge_cases.js +++ b/jstests/core/index_bounds_number_edge_cases.js @@ -6,7 +6,7 @@ t = db.indexboundsnumberedgecases; t.drop(); -t.ensureIndex({a: 1}); +t.createIndex({a: 1}); t.save({a: -Infinity}); t.save({a: -Number.MAX_VALUE}); diff --git a/jstests/core/index_check2.js b/jstests/core/index_check2.js index 8feeb7d42a8..216ca7fb283 100644 --- a/jstests/core/index_check2.js +++ b/jstests/core/index_check2.js @@ -32,7 +32,7 @@ assert.eq(120, t.find(q1).itcount(), "q1 a"); assert.eq(120, t.find(q2).itcount(), "q2 a"); assert.eq(60, t.find(q3).itcount(), "q3 a"); -t.ensureIndex({tags: 1}); +t.createIndex({tags: 1}); assert.eq(120, t.find(q1).itcount(), "q1 a"); assert.eq(120, t.find(q2).itcount(), "q2 a"); diff --git a/jstests/core/index_check3.js b/jstests/core/index_check3.js index 306b7415592..da472ecb0c9 100644 --- a/jstests/core/index_check3.js +++ b/jstests/core/index_check3.js @@ -14,7 +14,7 @@ t.save({a: "z"}); assert.eq(1, t.find({a: {$lt: 2}}).itcount(), "A"); assert.eq(1, t.find({a: {$gt: 2}}).itcount(), "B"); -t.ensureIndex({a: 1}); +t.createIndex({a: 1}); assert.eq(1, t.find({a: {$lt: 2}}).itcount(), "C"); assert.eq(1, t.find({a: {$gt: 2}}).itcount(), "D"); @@ -28,7 +28,7 @@ for (var i = 0; i < 100; i++) { t.save(o); } -t.ensureIndex({foo: 1}); +t.createIndex({foo: 1}); var explain = t.find({foo: {$lt: 50}}).explain("executionStats"); assert.gt(30, explain.executionStats.totalKeysExamined, "lt"); @@ -41,7 +41,7 @@ for (var i = 0; i < 10; ++i) { t.save({}); } -t.ensureIndex({i: 1}); +t.createIndex({i: 1}); var explain = t.find({i: {$lte: 'a'}}).explain("executionStats"); assert.gt(3, explain.executionStats.totalKeysExamined, "lte"); diff --git a/jstests/core/index_check5.js b/jstests/core/index_check5.js index 2a3e73f9e8d..8921e014fcd 100644 --- a/jstests/core/index_check5.js +++ b/jstests/core/index_check5.js @@ -14,5 +14,5 @@ t.save({ }); assert.eq(2, t.find({"scores.level": 2, "scores.score": {$gt: 30}}).itcount(), "A"); -t.ensureIndex({"scores.level": 1, "scores.score": 1}); +t.createIndex({"scores.level": 1, "scores.score": 1}); assert.eq(2, t.find({"scores.level": 2, "scores.score": {$gt: 30}}).itcount(), "B"); diff --git a/jstests/core/index_check6.js b/jstests/core/index_check6.js index 20310d2b0dd..646d64540cf 100644 --- a/jstests/core/index_check6.js +++ b/jstests/core/index_check6.js @@ -12,7 +12,7 @@ function keysExamined(query, hint) { return explain.executionStats.totalKeysExamined; } -t.ensureIndex({age: 1, rating: 1}); +t.createIndex({age: 1, rating: 1}); for (var age = 10; age < 50; age++) { for (var rating = 0; rating < 10; rating++) { @@ -98,7 +98,7 @@ for (var a = -1; a <= 1; a += 2) { for (var c = -1; c <= 1; c += 2) { t.dropIndexes(); var spec = {a: a, b: b, c: c}; - t.ensureIndex(spec); + t.createIndex(spec); doTest(spec, spec); doTest({a: -a, b: -b, c: -c}, spec); } diff --git a/jstests/core/index_check7.js b/jstests/core/index_check7.js index ae7ae7c9c71..4a4ac2a0aa1 100644 --- a/jstests/core/index_check7.js +++ b/jstests/core/index_check7.js @@ -9,10 +9,10 @@ t.drop(); for (var i = 0; i < 100; i++) t.save({x: i}); -t.ensureIndex({x: 1}); +t.createIndex({x: 1}); assert.eq(1, t.find({x: 27}).explain(true).executionStats.totalKeysExamined, "A"); -t.ensureIndex({x: -1}); +t.createIndex({x: -1}); assert.eq(1, t.find({x: 27}).explain(true).executionStats.totalKeysExamined, "B"); assert.eq(40, t.find({x: {$gt: 59}}).explain(true).executionStats.totalKeysExamined, "C"); diff --git a/jstests/core/index_diag.js b/jstests/core/index_diag.js index b336e5cc141..86f90c8d15c 100644 --- a/jstests/core/index_diag.js +++ b/jstests/core/index_diag.js @@ -49,7 +49,7 @@ if (FixtureHelpers.numberOfShardsForCollection(t) === 1) { assert.commandWorked(t.createIndex({_id: 1, x: 1})); assert.eq(all, t.find().hint({_id: 1, x: 1}).returnKey().toArray()); } -assert.commandWorked(t.ensureIndex({_id: 1, x: 1})); +assert.commandWorked(t.createIndex({_id: 1, x: 1})); assert.eq(r(all), t.find().hint({_id: 1, x: 1}).sort({x: 1}).returnKey().toArray()); assert.eq([{}, {}, {}], t.find().hint({$natural: 1}).returnKey().toArray()); diff --git a/jstests/core/index_dropdups_ignore.js b/jstests/core/index_dropdups_ignore.js index aabea228c26..0cc45d65648 100644 --- a/jstests/core/index_dropdups_ignore.js +++ b/jstests/core/index_dropdups_ignore.js @@ -11,13 +11,13 @@ t.insert({_id: 1, a: 'dup'}); t.insert({_id: 2, a: 'dup'}); // Should fail with a dup-key error even though dropDups is true; -var res = t.ensureIndex({a: 1}, {unique: true, dropDups: true}); +var res = t.createIndex({a: 1}, {unique: true, dropDups: true}); assert.commandFailed(res); assert.eq(res.code, 11000, tojson(res)); // Succeeds with the dup manually removed. t.remove({_id: 2}); -var res = t.ensureIndex({a: 1}, {unique: true, dropDups: true}); +var res = t.createIndex({a: 1}, {unique: true, dropDups: true}); assert.commandWorked(res); // The spec should have been stripped of the dropDups option. diff --git a/jstests/core/index_id_options.js b/jstests/core/index_id_options.js index 91bdce8090f..475a1a6fe95 100644 --- a/jstests/core/index_id_options.js +++ b/jstests/core/index_id_options.js @@ -21,12 +21,12 @@ var coll = db.getSiblingDB("local").index_id_options; // _id indexes must have key pattern {_id: 1}. coll.drop(); assert.commandWorked(coll.runCommand("create", {autoIndexId: false})); -assert.commandFailed(coll.ensureIndex({_id: -1}, {name: "_id_"})); +assert.commandFailed(coll.createIndex({_id: -1}, {name: "_id_"})); // The name of an _id index gets corrected to "_id_". coll.drop(); assert.commandWorked(coll.runCommand("create", {autoIndexId: false})); -assert.commandWorked(coll.ensureIndex({_id: 1}, {name: "bad"})); +assert.commandWorked(coll.createIndex({_id: 1}, {name: "bad"})); var spec = GetIndexHelpers.findByKeyPattern(coll.getIndexes(), {_id: 1}); assert.neq(null, spec, "_id index spec not found"); assert.eq("_id_", spec.name, tojson(spec)); @@ -34,35 +34,35 @@ assert.eq("_id_", spec.name, tojson(spec)); // _id indexes cannot have any options other than "key", "name", "ns", "v", and "collation." coll.drop(); assert.commandWorked(coll.runCommand("create", {autoIndexId: false})); -assert.commandFailed(coll.ensureIndex({_id: 1}, {name: "_id_", unique: true})); -assert.commandFailed(coll.ensureIndex({_id: 1}, {name: "_id_", sparse: false})); -assert.commandFailed(coll.ensureIndex({_id: 1}, {name: "_id_", partialFilterExpression: {a: 1}})); -assert.commandFailed(coll.ensureIndex({_id: 1}, {name: "_id_", expireAfterSeconds: 3600})); -assert.commandFailed(coll.ensureIndex({_id: 1}, {name: "_id_", background: false})); -assert.commandFailed(coll.ensureIndex({_id: 1}, {name: "_id_", unknown: true})); -assert.commandWorked(coll.ensureIndex( +assert.commandFailed(coll.createIndex({_id: 1}, {name: "_id_", unique: true})); +assert.commandFailed(coll.createIndex({_id: 1}, {name: "_id_", sparse: false})); +assert.commandFailed(coll.createIndex({_id: 1}, {name: "_id_", partialFilterExpression: {a: 1}})); +assert.commandFailed(coll.createIndex({_id: 1}, {name: "_id_", expireAfterSeconds: 3600})); +assert.commandFailed(coll.createIndex({_id: 1}, {name: "_id_", background: false})); +assert.commandFailed(coll.createIndex({_id: 1}, {name: "_id_", unknown: true})); +assert.commandWorked(coll.createIndex( {_id: 1}, {name: "_id_", ns: coll.getFullName(), v: 2, collation: {locale: "simple"}})); // _id indexes must have the collection default collation. coll.drop(); assert.commandWorked(coll.runCommand("create", {autoIndexId: false})); -assert.commandFailed(coll.ensureIndex({_id: 1}, {name: "_id_", collation: {locale: "en_US"}})); -assert.commandWorked(coll.ensureIndex({_id: 1}, {name: "_id_", collation: {locale: "simple"}})); +assert.commandFailed(coll.createIndex({_id: 1}, {name: "_id_", collation: {locale: "en_US"}})); +assert.commandWorked(coll.createIndex({_id: 1}, {name: "_id_", collation: {locale: "simple"}})); coll.drop(); assert.commandWorked(coll.runCommand("create", {autoIndexId: false})); -assert.commandWorked(coll.ensureIndex({_id: 1}, {name: "_id_"})); +assert.commandWorked(coll.createIndex({_id: 1}, {name: "_id_"})); coll.drop(); assert.commandWorked(coll.runCommand("create", {autoIndexId: false, collation: {locale: "en_US"}})); -assert.commandFailed(coll.ensureIndex({_id: 1}, {name: "_id_", collation: {locale: "simple"}})); -assert.commandFailed(coll.ensureIndex({_id: 1}, {name: "_id_", collation: {locale: "fr_CA"}})); +assert.commandFailed(coll.createIndex({_id: 1}, {name: "_id_", collation: {locale: "simple"}})); +assert.commandFailed(coll.createIndex({_id: 1}, {name: "_id_", collation: {locale: "fr_CA"}})); assert.commandWorked( - coll.ensureIndex({_id: 1}, {name: "_id_", collation: {locale: "en_US", strength: 3}})); + coll.createIndex({_id: 1}, {name: "_id_", collation: {locale: "en_US", strength: 3}})); coll.drop(); assert.commandWorked(coll.runCommand("create", {autoIndexId: false, collation: {locale: "en_US"}})); -assert.commandWorked(coll.ensureIndex({_id: 1}, {name: "_id_"})); +assert.commandWorked(coll.createIndex({_id: 1}, {name: "_id_"})); spec = GetIndexHelpers.findByName(coll.getIndexes(), "_id_"); assert.neq(null, spec, "_id index spec not found"); assert.eq("en_US", spec.collation.locale, tojson(spec)); @@ -70,6 +70,6 @@ assert.eq("en_US", spec.collation.locale, tojson(spec)); // Non-_id indexes cannot have the name "_id_". coll.drop(); assert.commandWorked(coll.runCommand("create", {autoIndexId: false})); -assert.commandFailed(coll.ensureIndex({_id: "hashed"}, {name: "_id_"})); -assert.commandFailed(coll.ensureIndex({a: 1}, {name: "_id_"})); +assert.commandFailed(coll.createIndex({_id: "hashed"}, {name: "_id_"})); +assert.commandFailed(coll.createIndex({a: 1}, {name: "_id_"})); })(); diff --git a/jstests/core/index_many.js b/jstests/core/index_many.js index f95d4ac50de..cdd559c9be5 100644 --- a/jstests/core/index_many.js +++ b/jstests/core/index_many.js @@ -22,7 +22,7 @@ function f() { patt = {x: 1}; if (x == 64) patt = {y: 1}; - lastErr = t.ensureIndex(patt); + lastErr = t.createIndex(patt); x++; } diff --git a/jstests/core/index_many2.js b/jstests/core/index_many2.js index f6f6b0cb392..70fada7396e 100644 --- a/jstests/core/index_many2.js +++ b/jstests/core/index_many2.js @@ -16,7 +16,7 @@ function make(n) { } for (i = 1; i < 1000; i++) { - t.ensureIndex(make(i)); + t.createIndex(make(i)); } assert.eq(64, t.getIndexKeys().length, "A2"); @@ -26,7 +26,7 @@ num = t.getIndexKeys().length; t.dropIndex(make(num - 1)); assert.eq(num - 1, t.getIndexKeys().length, "B0"); -t.ensureIndex({z: 1}); +t.createIndex({z: 1}); assert.eq(num, t.getIndexKeys().length, "B1"); t.dropIndexes("*"); diff --git a/jstests/core/index_partial_validate.js b/jstests/core/index_partial_validate.js index 2319aac2954..5011b4b8bc2 100644 --- a/jstests/core/index_partial_validate.js +++ b/jstests/core/index_partial_validate.js @@ -6,10 +6,10 @@ var t = db.index_partial_validate; t.drop(); -var res = t.ensureIndex({a: 1}, {partialFilterExpression: {a: {$lte: 1}}}); +var res = t.createIndex({a: 1}, {partialFilterExpression: {a: {$lte: 1}}}); assert.commandWorked(res); -res = t.ensureIndex({b: 1}); +res = t.createIndex({b: 1}); assert.commandWorked(res); res = t.insert({non_indexed_field: 'x'}); diff --git a/jstests/core/index_partial_write_ops.js b/jstests/core/index_partial_write_ops.js index df80ac33b42..6adcb8933fd 100644 --- a/jstests/core/index_partial_write_ops.js +++ b/jstests/core/index_partial_write_ops.js @@ -21,7 +21,7 @@ var getNumKeys = function(idxName) { coll.drop(); // Create partial index. -assert.commandWorked(coll.ensureIndex({x: 1}, {unique: true, partialFilterExpression: {a: 1}})); +assert.commandWorked(coll.createIndex({x: 1}, {unique: true, partialFilterExpression: {a: 1}})); assert.commandWorked(coll.insert({_id: 1, x: 5, a: 2, b: 1})); // Not in index. assert.commandWorked(coll.insert({_id: 2, x: 6, a: 1, b: 1})); // In index. diff --git a/jstests/core/index_sparse1.js b/jstests/core/index_sparse1.js index a7c1e8605ef..58bc5baa9b8 100644 --- a/jstests/core/index_sparse1.js +++ b/jstests/core/index_sparse1.js @@ -14,13 +14,13 @@ t.insert({_id: 5}); assert.eq(5, t.count(), "A1"); assert.eq(5, t.find().sort({x: 1}).itcount(), "A2"); -t.ensureIndex({x: 1}); +t.createIndex({x: 1}); assert.eq(2, t.getIndexes().length, "B1"); assert.eq(5, t.find().sort({x: 1}).itcount(), "B2"); t.dropIndex({x: 1}); assert.eq(1, t.getIndexes().length, "B3"); -t.ensureIndex({x: 1}, {sparse: 1}); +t.createIndex({x: 1}, {sparse: 1}); assert.eq(2, t.getIndexes().length, "C1"); assert.eq(5, t.find().sort({x: 1}).itcount(), "C2"); t.dropIndex({x: 1}); @@ -31,14 +31,14 @@ assert.eq(1, t.getIndexes().length, "C3"); t.remove({_id: 2}); // test that we can't create a unique index without sparse -assert.commandFailed(t.ensureIndex({x: 1}, {unique: 1})); +assert.commandFailed(t.createIndex({x: 1}, {unique: 1})); assert.eq(1, t.getIndexes().length, "D2"); -t.ensureIndex({x: 1}, {unique: 1, sparse: 1}); +t.createIndex({x: 1}, {unique: 1, sparse: 1}); assert.eq(2, t.getIndexes().length, "E1"); t.dropIndex({x: 1}); assert.eq(1, t.getIndexes().length, "E3"); t.insert({_id: 2, x: 2}); -t.ensureIndex({x: 1}, {unique: 1, sparse: 1}); +t.createIndex({x: 1}, {unique: 1, sparse: 1}); assert.eq(1, t.getIndexes().length, "F1"); diff --git a/jstests/core/index_sparse2.js b/jstests/core/index_sparse2.js index 148ad70b203..324b46d8216 100644 --- a/jstests/core/index_sparse2.js +++ b/jstests/core/index_sparse2.js @@ -9,14 +9,14 @@ t.insert({_id: 1, x: 1, y: 1}); t.insert({_id: 2, x: 2}); t.insert({_id: 3}); -t.ensureIndex({x: 1, y: 1}); +t.createIndex({x: 1, y: 1}); assert.eq(2, t.getIndexes().length, "A1"); assert.eq(3, t.find().sort({x: 1, y: 1}).count(), "A2 count()"); assert.eq(3, t.find().sort({x: 1, y: 1}).itcount(), "A2 itcount()"); t.dropIndex({x: 1, y: 1}); assert.eq(1, t.getIndexes().length, "A3"); -t.ensureIndex({x: 1, y: 1}, {sparse: 1}); +t.createIndex({x: 1, y: 1}, {sparse: 1}); assert.eq(2, t.getIndexes().length, "B1"); assert.eq(3, t.find().sort({x: 1, y: 1}).count(), "B2 count()"); assert.eq(3, t.find().sort({x: 1, y: 1}).itcount(), "B2 itcount()"); diff --git a/jstests/core/index_type_change.js b/jstests/core/index_type_change.js index 4ecb5081347..d23984a132d 100644 --- a/jstests/core/index_type_change.js +++ b/jstests/core/index_type_change.js @@ -18,7 +18,7 @@ load("jstests/libs/analyze_plan.js"); // For 'isIndexOnly'. var coll = db.index_type_change; coll.drop(); -assert.commandWorked(coll.ensureIndex({a: 1})); +assert.commandWorked(coll.createIndex({a: 1})); assert.commandWorked(coll.insert({a: 2})); assert.eq(1, coll.find({a: {$type: "double"}}).itcount()); diff --git a/jstests/core/indexa.js b/jstests/core/indexa.js index 90e74adc4f4..01fde035621 100644 --- a/jstests/core/indexa.js +++ b/jstests/core/indexa.js @@ -8,7 +8,7 @@ t = db.indexa; t.drop(); -t.ensureIndex({x: 1}, true); +t.createIndex({x: 1}, true); t.insert({'x': 'A'}); t.insert({'x': 'B'}); diff --git a/jstests/core/indexapi.js b/jstests/core/indexapi.js index 14cf634e556..29d39ea721b 100644 --- a/jstests/core/indexapi.js +++ b/jstests/core/indexapi.js @@ -31,14 +31,14 @@ c.dropDups = true; assert.eq(c, t._indexSpec({x: 1}, [true, true]), "G"); assert.eq(c, t._indexSpec({x: 1}, {unique: true, dropDups: true}), "F"); -t.ensureIndex({x: 1}, {unique: true}); +t.createIndex({x: 1}, {unique: true}); idx = t.getIndexes(); assert.eq(2, idx.length, "M1"); assert.eq(key, idx[1].key, "M2"); assert(idx[1].unique, "M3"); t.drop(); -t.ensureIndex({x: 1}, {unique: 1}); +t.createIndex({x: 1}, {unique: 1}); idx = t.getIndexes(); assert.eq(2, idx.length, "M1"); assert.eq(key, idx[1].key, "M2"); diff --git a/jstests/core/indexb.js b/jstests/core/indexb.js index 6890dda3cbc..59546f7fae2 100644 --- a/jstests/core/indexb.js +++ b/jstests/core/indexb.js @@ -10,7 +10,7 @@ t = db.indexb; t.drop(); -t.ensureIndex({a: 1}, true); +t.createIndex({a: 1}, true); t.insert({a: 1}); diff --git a/jstests/core/indexc.js b/jstests/core/indexc.js index 3bc4c9eaca8..bf5735380fa 100644 --- a/jstests/core/indexc.js +++ b/jstests/core/indexc.js @@ -13,8 +13,8 @@ for (var i = 1; i < 100; i++) { assert.eq(50, t.find({ts: {$lt: mid}}).itcount(), "A"); assert.eq(50, t.find({ts: {$lt: mid}}).sort({ts: 1}).itcount(), "B"); -t.ensureIndex({ts: 1, cats: 1}); -t.ensureIndex({cats: 1}); +t.createIndex({ts: 1, cats: 1}); +t.createIndex({cats: 1}); // multi-key bug was firing here (related to getsetdup()): assert.eq(50, t.find({ts: {$lt: mid}}).itcount(), "C"); diff --git a/jstests/core/indexe.js b/jstests/core/indexe.js index 6961229c682..a307882adc3 100644 --- a/jstests/core/indexe.js +++ b/jstests/core/indexe.js @@ -13,7 +13,7 @@ assert.eq(num, t.find().count(), "A1"); assert.eq(num, t.find({a: "b"}).count(), "B1"); assert.eq(num, t.find({a: "b"}).itcount(), "C1"); -t.ensureIndex({a: 1}); +t.createIndex({a: 1}); assert.eq(num, t.find().count(), "A2"); assert.eq(num, t.find().sort({a: 1}).count(), "A2a"); diff --git a/jstests/core/indexf.js b/jstests/core/indexf.js index cbe1b968b5e..4dc8fb0b060 100644 --- a/jstests/core/indexf.js +++ b/jstests/core/indexf.js @@ -7,7 +7,7 @@ t = db.indexf; t.drop(); -t.ensureIndex({x: 1}); +t.createIndex({x: 1}); t.save({x: 2}); t.save({y: 3}); diff --git a/jstests/core/indexg.js b/jstests/core/indexg.js index 3cafede4cff..486f4be0ebe 100644 --- a/jstests/core/indexg.js +++ b/jstests/core/indexg.js @@ -9,5 +9,5 @@ doit = function() { assert.eq(1, f.count({list: {$in: [1], $not: {$in: [3]}}})); }; doit(); -f.ensureIndex({list: 1}); +f.createIndex({list: 1}); doit();
\ No newline at end of file diff --git a/jstests/core/indexj.js b/jstests/core/indexj.js index 76bf8cb17e9..64cf9844d7f 100644 --- a/jstests/core/indexj.js +++ b/jstests/core/indexj.js @@ -20,12 +20,12 @@ function keysExamined(query, hint, sort) { return explain.executionStats.totalKeysExamined; } -t.ensureIndex({a: 1}); +t.createIndex({a: 1}); t.save({a: 5}); assert.eq(0, keysExamined({a: {$gt: 4, $lt: 5}}), "A"); t.drop(); -t.ensureIndex({a: 1}); +t.createIndex({a: 1}); t.save({a: 4}); assert.eq(0, keysExamined({a: {$gt: 4, $lt: 5}}), "B"); @@ -39,7 +39,7 @@ t.save({a: 5}); assert.eq(0, keysExamined({a: {$gt: 4, $lt: 5}}), "D"); t.drop(); -t.ensureIndex({a: 1, b: 1}); +t.createIndex({a: 1, b: 1}); t.save({a: 1, b: 1}); t.save({a: 1, b: 2}); t.save({a: 2, b: 1}); diff --git a/jstests/core/indexl.js b/jstests/core/indexl.js index c83638607d4..cde169eda71 100644 --- a/jstests/core/indexl.js +++ b/jstests/core/indexl.js @@ -23,5 +23,5 @@ function test(t) { t.drop(); test(t); t.drop(); -t.ensureIndex({a: 1}); +t.createIndex({a: 1}); test(t);
\ No newline at end of file diff --git a/jstests/core/indexm.js b/jstests/core/indexm.js index 820bedd7baa..7613b125357 100644 --- a/jstests/core/indexm.js +++ b/jstests/core/indexm.js @@ -13,12 +13,12 @@ function test() { test(); // Now create an index. -t.ensureIndex({"a": 1}); +t.createIndex({"a": 1}); test(); // Now create a different index. t.dropIndexes(); -t.ensureIndex({"a.x": 1}); +t.createIndex({"a.x": 1}); test(); // Drop the indexes. diff --git a/jstests/core/indexn.js b/jstests/core/indexn.js index 014ba050cbc..02547280ad9 100644 --- a/jstests/core/indexn.js +++ b/jstests/core/indexn.js @@ -9,8 +9,8 @@ t.drop(); t.save({a: 1, b: [1, 2]}); -t.ensureIndex({a: 1}); -t.ensureIndex({b: 1}); +t.createIndex({a: 1}); +t.createIndex({b: 1}); // {a:1} is a single key index, so no matches are possible for this query assert.eq(0, t.count({a: {$gt: 5, $lt: 0}})); diff --git a/jstests/core/indexp.js b/jstests/core/indexp.js index 71e9f8eadb9..8199e0f132c 100644 --- a/jstests/core/indexp.js +++ b/jstests/core/indexp.js @@ -6,18 +6,18 @@ var coll = db.jstests_indexp; // Empty field checks. -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})); +assert.commandFailed(coll.createIndex({'a..b': 1})); +assert.commandFailed(coll.createIndex({'.a': 1})); +assert.commandFailed(coll.createIndex({'a.': 1})); +assert.commandFailed(coll.createIndex({'.': 1})); +assert.commandFailed(coll.createIndex({'': 1})); +assert.commandWorked(coll.createIndex({'a.b': 1})); // '$'-prefixed field checks. -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 +assert.commandFailed(coll.createIndex({'$a': 1})); +assert.commandFailed(coll.createIndex({'a.$b': 1})); +assert.commandFailed(coll.createIndex({'$db': 1})); +assert.commandWorked(coll.createIndex({'a$ap': 1})); // $ in middle is ok +assert.commandWorked(coll.createIndex({'a.$id': 1})); // $id/$db/$ref are execptions coll.dropIndexes(); diff --git a/jstests/core/indexr.js b/jstests/core/indexr.js index 15cd56e9681..de3afe8cdc1 100644 --- a/jstests/core/indexr.js +++ b/jstests/core/indexr.js @@ -15,8 +15,8 @@ assert.eq(1, t.count({a: {b: 3, c: 6}, 'a.c': {$lt: 4}})); // Check with single key indexes. t.remove({}); -t.ensureIndex({'a.b': 1, 'a.c': 1}); -t.ensureIndex({a: 1, 'a.c': 1}); +t.createIndex({'a.b': 1, 'a.c': 1}); +t.createIndex({a: 1, 'a.c': 1}); assert.eq(0, t.count({'a.b': {$gt: 2}, 'a.c': {$lt: 4}})); assert.eq(0, t.count({a: {b: 3, c: 6}, 'a.c': {$lt: 4}})); diff --git a/jstests/core/indexs.js b/jstests/core/indexs.js index 2fc9724a590..6ee625071e2 100644 --- a/jstests/core/indexs.js +++ b/jstests/core/indexs.js @@ -4,16 +4,16 @@ t = db.jstests_indexs; t.drop(); -t.ensureIndex({a: 1}); +t.createIndex({a: 1}); t.save({a: [{b: 3}]}); assert.eq(1, t.count({a: {b: 3}})); t.drop(); -t.ensureIndex({a: 1, 'a.b': 1}); +t.createIndex({a: 1, 'a.b': 1}); t.save({a: {b: 3}}); assert.eq(1, t.count({a: {b: 3}})); t.drop(); -t.ensureIndex({a: 1, 'a.b': 1}); +t.createIndex({a: 1, 'a.b': 1}); t.save({a: [{b: 3}]}); assert.eq(1, t.count({a: {b: 3}})); diff --git a/jstests/core/indext.js b/jstests/core/indext.js index 163a3e4a8a3..1ac92d6be5d 100644 --- a/jstests/core/indext.js +++ b/jstests/core/indext.js @@ -3,12 +3,12 @@ t = db.jstests_indext; t.drop(); -t.ensureIndex({'a.b': 1}, {sparse: true}); +t.createIndex({'a.b': 1}, {sparse: true}); t.save({a: []}); t.save({a: 1}); assert.eq(0, t.find().hint({'a.b': 1}).itcount()); -t.ensureIndex({'a.b': 1, 'a.c': 1}, {sparse: true}); +t.createIndex({'a.b': 1, 'a.c': 1}, {sparse: true}); t.save({a: []}); t.save({a: 1}); assert.eq(0, t.find().hint({'a.b': 1, 'a.c': 1}).itcount()); diff --git a/jstests/core/indexu.js b/jstests/core/indexu.js index 22af42d5d6a..973fc0e4985 100644 --- a/jstests/core/indexu.js +++ b/jstests/core/indexu.js @@ -15,56 +15,56 @@ var noDupDoc = {a: [{'1': 1}]}; // Test that we can't index dupDoc. assert.commandWorked(t.save(dupDoc)); -assert.commandFailedWithCode(t.ensureIndex({'a.0': 1}), 16746); +assert.commandFailedWithCode(t.createIndex({'a.0': 1}), 16746); // Test that we can fail gracefully when dupDoc has a large array padded with nulls. // Index is based on max padding constant in mongo/db/update/path_support.h assert.commandWorked(t.update({_id: 0}, {$set: {'a.1500001': 1}})); -assert.commandFailedWithCode(t.ensureIndex({'a.0': 1}), 16746); +assert.commandFailedWithCode(t.createIndex({'a.0': 1}), 16746); t.remove({}); -assert.commandWorked(t.ensureIndex({'a.0': 1})); +assert.commandWorked(t.createIndex({'a.0': 1})); assert.writeError(t.save(dupDoc)); // Test that we can't index dupDoc2. t.drop(); assert.commandWorked(t.save(dupDoc2)); -assert.commandFailedWithCode(t.ensureIndex({'a.1': 1}), 16746); +assert.commandFailedWithCode(t.createIndex({'a.1': 1}), 16746); t.remove({}); -assert.commandWorked(t.ensureIndex({'a.1': 1})); +assert.commandWorked(t.createIndex({'a.1': 1})); assert.writeError(t.save(dupDoc2)); // Test that we can index dupDoc with a different index. t.drop(); -t.ensureIndex({'a.b': 1}); +t.createIndex({'a.b': 1}); assert.commandWorked(t.save(dupDoc)); // Test number field starting with hyphen. t.drop(); -t.ensureIndex({'a.-1': 1}); +t.createIndex({'a.-1': 1}); assert.commandWorked(t.save({a: [{'-1': 1}]})); // Test number field starting with zero. t.drop(); -t.ensureIndex({'a.00': 1}); +t.createIndex({'a.00': 1}); assert.commandWorked(t.save({a: [{'00': 1}]})); // Test multiple array indexes t.drop(); -t.ensureIndex({'a.0': 1, 'a.1': 1}); +t.createIndex({'a.0': 1, 'a.1': 1}); assert.commandWorked(t.save({a: [{'1': 1}]})); assert.writeError(t.save({a: [{'1': 1}, 4]})); // Test that we can index noDupDoc. t.drop(); t.save(noDupDoc); -assert.commandWorked(t.ensureIndex({'a.0': 1})); -assert.commandWorked(t.ensureIndex({'a.1': 1})); +assert.commandWorked(t.createIndex({'a.0': 1})); +assert.commandWorked(t.createIndex({'a.1': 1})); t.drop(); -t.ensureIndex({'a.0': 1}); -t.ensureIndex({'a.1': 1}); +t.createIndex({'a.0': 1}); +t.createIndex({'a.1': 1}); assert.commandWorked(t.save(noDupDoc)); // Test that we can query noDupDoc. @@ -76,7 +76,7 @@ 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.commandWorked(t.ensureIndex({'a.0.0': 1})); +assert.commandWorked(t.createIndex({'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()); @@ -84,36 +84,36 @@ assert.eq(1, t.find({'a.0.0': 1}).hint({'a.0.0': 1}).itcount()); // field. t.drop(); t.save({a: [[1], {'0': 1}]}); -assert.commandFailed(t.ensureIndex({'a.0.0': 1})); +assert.commandFailed(t.createIndex({'a.0.0': 1})); // Check where there is a duplicate for a fully addressed field. t.drop(); assert.commandWorked(t.save({a: [[1], {'0': [1]}]})); -assert.commandFailedWithCode(t.ensureIndex({'a.0.0': 1}), 16746); +assert.commandFailedWithCode(t.createIndex({'a.0.0': 1}), 16746); // Two ways of addressing parse to an array. t.drop(); t.save({a: [{'0': 1}]}); -assert.commandFailedWithCode(t.ensureIndex({'a.0.0': 1}), 16746); +assert.commandFailedWithCode(t.createIndex({'a.0.0': 1}), 16746); // Test several key depths - with same arrays being found. t.drop(); t.save({a: [{'0': [{'0': 1}]}]}); -assert.commandFailedWithCode(t.ensureIndex({'a.0.0.0.0.0.0': 1}), 16746); -assert.commandFailedWithCode(t.ensureIndex({'a.0.0.0.0.0': 1}), 16746); -assert.commandFailedWithCode(t.ensureIndex({'a.0.0.0.0': 1}), 16746); -assert.commandFailedWithCode(t.ensureIndex({'a.0.0.0': 1}), 16746); -assert.commandFailedWithCode(t.ensureIndex({'a.0.0': 1}), 16746); -assert.commandFailedWithCode(t.ensureIndex({'a.0': 1}), 16746); -assert.commandWorked(t.ensureIndex({'a': 1})); +assert.commandFailedWithCode(t.createIndex({'a.0.0.0.0.0.0': 1}), 16746); +assert.commandFailedWithCode(t.createIndex({'a.0.0.0.0.0': 1}), 16746); +assert.commandFailedWithCode(t.createIndex({'a.0.0.0.0': 1}), 16746); +assert.commandFailedWithCode(t.createIndex({'a.0.0.0': 1}), 16746); +assert.commandFailedWithCode(t.createIndex({'a.0.0': 1}), 16746); +assert.commandFailedWithCode(t.createIndex({'a.0': 1}), 16746); +assert.commandWorked(t.createIndex({'a': 1})); // Two prefixes extract docs, but one terminates extraction before array. t.drop(); t.save({a: [{'0': {'c': []}}]}); -assert.commandFailedWithCode(t.ensureIndex({'a.0.c': 1}), 16746); +assert.commandFailedWithCode(t.createIndex({'a.0.c': 1}), 16746); t.drop(); t.save({a: [[{'b': 1}]]}); assert.eq(1, t.find({'a.0.b': 1}).itcount()); -t.ensureIndex({'a.0.b': 1}); +t.createIndex({'a.0.b': 1}); assert.eq(1, t.find({'a.0.b': 1}).itcount()); diff --git a/jstests/core/insert_illegal_doc.js b/jstests/core/insert_illegal_doc.js index 64ecb0ae7ad..f6344f1c62b 100644 --- a/jstests/core/insert_illegal_doc.js +++ b/jstests/core/insert_illegal_doc.js @@ -2,7 +2,7 @@ // "parallel indexing of arrays" test var coll = db.insert_illegal_doc; coll.drop(); -coll.ensureIndex({a: 1, b: 1}); +coll.createIndex({a: 1, b: 1}); var res; // test upsert diff --git a/jstests/core/js3.js b/jstests/core/js3.js index 89847210714..8698195d6c4 100644 --- a/jstests/core/js3.js +++ b/jstests/core/js3.js @@ -18,8 +18,8 @@ for (z = 0; z < 2; z++) { t.drop(); if (z > 0) { - t.ensureIndex({_id: 1}); - t.ensureIndex({i: 1}); + t.createIndex({_id: 1}); + t.createIndex({i: 1}); } for (i = 0; i < 1000; i++) @@ -51,8 +51,8 @@ for (z = 0; z < 2; z++) { debug(ok); assert(ok); - t.ensureIndex({z: 1}); - t.ensureIndex({q: 1}); + t.createIndex({z: 1}); + t.createIndex({q: 1}); debug("before indexed find"); diff --git a/jstests/core/list_indexes.js b/jstests/core/list_indexes.js index 040d30e6290..a81a1adf68a 100644 --- a/jstests/core/list_indexes.js +++ b/jstests/core/list_indexes.js @@ -59,7 +59,7 @@ assert.eq(["_id_"], cursorGetIndexNames(getListIndexesCursor(coll))); coll.drop(); assert.commandWorked(coll.getDB().createCollection(coll.getName())); -assert.commandWorked(coll.ensureIndex({a: 1}, {unique: true})); +assert.commandWorked(coll.createIndex({a: 1}, {unique: true})); specs = cursorGetIndexSpecs(getListIndexesCursor(coll)); assert.eq(2, specs.length); assert.eq("_id_", specs[0].name); @@ -84,7 +84,7 @@ assert.commandFailed(coll.getDB().runCommand({listIndexes: []})); coll.drop(); assert.commandWorked(coll.getDB().createCollection(coll.getName())); -assert.commandWorked(coll.ensureIndex({a: 1}, {unique: true})); +assert.commandWorked(coll.createIndex({a: 1}, {unique: true})); cursor = getListIndexesCursor(coll, {cursor: {batchSize: 2}}); assert.eq(2, cursor.objsLeftInBatch()); @@ -124,9 +124,9 @@ assert.eq(["_id_", "a_1"], cursorGetIndexNames(cursor)); coll.drop(); assert.commandWorked(coll.getDB().createCollection(coll.getName())); -assert.commandWorked(coll.ensureIndex({a: 1}, {unique: true})); -assert.commandWorked(coll.ensureIndex({b: 1}, {unique: true})); -assert.commandWorked(coll.ensureIndex({c: 1}, {unique: true})); +assert.commandWorked(coll.createIndex({a: 1}, {unique: true})); +assert.commandWorked(coll.createIndex({b: 1}, {unique: true})); +assert.commandWorked(coll.createIndex({c: 1}, {unique: true})); cursor = getListIndexesCursor(coll, {cursor: {batchSize: 0}}, 2); assert.eq(0, cursor.objsLeftInBatch()); @@ -167,9 +167,9 @@ if (!FixtureHelpers.isMongos(db)) { coll.drop(); assert.commandWorked(coll.getDB().createCollection(coll.getName())); -assert.commandWorked(coll.ensureIndex({a: 1}, {unique: true})); -assert.commandWorked(coll.ensureIndex({b: 1}, {unique: true})); -assert.commandWorked(coll.ensureIndex({c: 1}, {unique: true})); +assert.commandWorked(coll.createIndex({a: 1}, {unique: true})); +assert.commandWorked(coll.createIndex({b: 1}, {unique: true})); +assert.commandWorked(coll.createIndex({c: 1}, {unique: true})); res = coll.runCommand("listIndexes", {cursor: {batchSize: 0}}); cursor = new DBCommandCursor(coll.getDB(), res, 2); diff --git a/jstests/core/list_indexes_invalid.js b/jstests/core/list_indexes_invalid.js index 43d64a594c2..7b73a4278ce 100644 --- a/jstests/core/list_indexes_invalid.js +++ b/jstests/core/list_indexes_invalid.js @@ -8,7 +8,7 @@ var coll = db.list_indexes_invalid; coll.drop(); assert.commandWorked(coll.getDB().createCollection(coll.getName())); -assert.commandWorked(coll.ensureIndex({a: 1}, {unique: true})); +assert.commandWorked(coll.createIndex({a: 1}, {unique: true})); assert.throws(function() { getListIndexesCursor(coll, {cursor: 0}); diff --git a/jstests/core/minmax.js b/jstests/core/minmax.js index 14f4ed0ec2c..b4f181689a2 100644 --- a/jstests/core/minmax.js +++ b/jstests/core/minmax.js @@ -16,7 +16,7 @@ function addData() { assert.commandWorked(coll.save({a: 2, b: 2})); } -assert.commandWorked(coll.ensureIndex({a: 1, b: 1})); +assert.commandWorked(coll.createIndex({a: 1, b: 1})); addData(); assert.eq(1, coll.find().hint({a: 1, b: 1}).min({a: 1, b: 2}).max({a: 2, b: 1}).toArray().length); @@ -31,7 +31,7 @@ assert.eq(3, coll.find().hint({a: 1, b: 1}).max({a: 2, b: 1.5}).hint({a: 1, b: 1}).toArray().length); coll.drop(); -assert.commandWorked(coll.ensureIndex({a: 1, b: -1})); +assert.commandWorked(coll.createIndex({a: 1, b: -1})); addData(); assert.eq(4, coll.find().hint({a: 1, b: -1}).min({a: 1, b: 2}).toArray().length); assert.eq(4, coll.find().hint({a: 1, b: -1}).max({a: 2, b: 0.5}).toArray().length); @@ -78,7 +78,7 @@ error = assert.throws(function() { assert.eq(error.code, ErrorCodes.NoQueryExecutionPlans); coll.drop(); -assert.commandWorked(coll.ensureIndex({a: 1})); +assert.commandWorked(coll.createIndex({a: 1})); for (let i = 0; i < 10; ++i) { assert.commandWorked(coll.save({_id: i, a: i})); } @@ -103,7 +103,7 @@ assert.eq(error.code, 51175); coll.drop(); addData(); -assert.commandWorked(coll.ensureIndex({a: 1, b: 1})); +assert.commandWorked(coll.createIndex({a: 1, b: 1})); error = assert.throws(function() { coll.find().min({a: 1, b: 2}).max({a: 1, b: 2}).hint({a: 1, b: 1}).toArray(); @@ -112,7 +112,7 @@ assert.eq(error.code, 51175); // Test ascending index. coll.drop(); -assert.commandWorked(coll.ensureIndex({a: 1})); +assert.commandWorked(coll.createIndex({a: 1})); assert.commandWorked(coll.insert({a: 3})); assert.commandWorked(coll.insert({a: 4})); assert.commandWorked(coll.insert({a: 5})); @@ -134,7 +134,7 @@ assert(!cursor.hasNext()); // Test descending index. assert.commandWorked(coll.dropIndexes()); -assert.commandWorked(coll.ensureIndex({a: -1})); +assert.commandWorked(coll.createIndex({a: -1})); cursor = coll.find().hint({a: -1}).min({a: 4}); if (FixtureHelpers.numberOfShardsForCollection(coll) === 1) { diff --git a/jstests/core/mr_multikey_deduping.js b/jstests/core/mr_multikey_deduping.js index 604635a67fc..e3f729ef16f 100644 --- a/jstests/core/mr_multikey_deduping.js +++ b/jstests/core/mr_multikey_deduping.js @@ -39,7 +39,7 @@ outColl.drop(); assert(outColl.drop()); // Now test that we get the same results when there's an index present. - assert.commandWorked(coll.ensureIndex({arr: 1})); + assert.commandWorked(coll.createIndex({arr: 1})); res = assert.commandWorked(coll.mapReduce( mapFn, reduceFn, {out: {merge: outColl.getName()}, query: {arr: {$gte: 0}}})); assert(outColl.drop()); @@ -93,7 +93,7 @@ outColl.drop(); resultsEq([{_id: "cat", value: 1}, {_id: "dog", value: 1}], resultsNoIndexEqualityOnName)); assert(resultsEq(resultsNoIndexNoQuery, resultsNoIndexRangeOnName)); - assert.commandWorked(coll.ensureIndex({name: 1, tags: 1})); + assert.commandWorked(coll.createIndex({name: 1, tags: 1})); const resultsIndexedNoQuery = assert diff --git a/jstests/core/mr_sort.js b/jstests/core/mr_sort.js index df98e6a6d3d..c1ce7d3861b 100644 --- a/jstests/core/mr_sort.js +++ b/jstests/core/mr_sort.js @@ -12,7 +12,7 @@ t = db.mr_sort; t.drop(); -t.ensureIndex({x: 1}); +t.createIndex({x: 1}); t.insert({x: 1}); t.insert({x: 10}); diff --git a/jstests/core/multi.js b/jstests/core/multi.js index c7853b18f25..ac961ed7a9c 100644 --- a/jstests/core/multi.js +++ b/jstests/core/multi.js @@ -1,7 +1,7 @@ t = db.jstests_multi; t.drop(); -t.ensureIndex({a: 1}); +t.createIndex({a: 1}); t.save({a: [1, 2]}); assert.eq(1, t.find({a: {$gt: 0}}).count(), "A"); assert.eq(1, t.find({a: {$gt: 0}}).toArray().length, "B"); diff --git a/jstests/core/multi2.js b/jstests/core/multi2.js index 8c1c4ea5f3c..64473e4de98 100644 --- a/jstests/core/multi2.js +++ b/jstests/core/multi2.js @@ -10,13 +10,13 @@ t.save({}); assert.eq(3, t.find({x: 1}).count(), "A"); -t.ensureIndex({x: 1}); +t.createIndex({x: 1}); assert.eq(3, t.find({x: 1}).count(), "B"); assert.eq(4, t.find().sort({x: 1, a: 1}).count(), "s1"); assert.eq(1, t.find({x: 1, a: null}).count(), "B2"); t.dropIndex({x: 1}); -t.ensureIndex({x: 1, a: 1}); +t.createIndex({x: 1, a: 1}); assert.eq(3, t.find({x: 1}).count(), "C"); // SERVER-279 assert.eq(4, t.find().sort({x: 1, a: 1}).count(), "s2"); assert.eq(1, t.find({x: 1, a: null}).count(), "C2"); diff --git a/jstests/core/multikey_geonear.js b/jstests/core/multikey_geonear.js index ad24afb0c98..4b1cd5eb482 100644 --- a/jstests/core/multikey_geonear.js +++ b/jstests/core/multikey_geonear.js @@ -16,7 +16,7 @@ function checkResults(cursor) { assert(!cursor.hasNext()); } -t.ensureIndex({a: 1, b: "2dsphere"}); +t.createIndex({a: 1, b: "2dsphere"}); t.insert({_id: 0, a: 0, b: {type: "Point", coordinates: [0, 0]}}); t.insert({_id: 1, a: 0, b: {type: "Point", coordinates: [1, 1]}}); @@ -33,7 +33,7 @@ checkResults(cursor); // Repeat these tests for a 2d index. t.drop(); -t.ensureIndex({a: "2d", b: 1}); +t.createIndex({a: "2d", b: 1}); t.insert({_id: 0, a: [0, 0], b: 0}); t.insert({_id: 1, a: [1, 1], b: 1}); t.insert({_id: 2, a: [2, 2], b: 2}); @@ -47,7 +47,7 @@ checkResults(cursor); // The fields in the compound 2dsphere index share a prefix. t.drop(); -t.ensureIndex({"a.b": 1, "a.c": "2dsphere"}); +t.createIndex({"a.b": 1, "a.c": "2dsphere"}); t.insert({_id: 0, a: [{b: 0}, {c: {type: "Point", coordinates: [0, 0]}}]}); t.insert({_id: 1, a: [{b: 1}, {c: {type: "Point", coordinates: [1, 1]}}]}); t.insert({_id: 2, a: [{b: 2}, {c: {type: "Point", coordinates: [2, 2]}}]}); @@ -66,7 +66,7 @@ assert(!cursor.hasNext()); // The fields in the compound 2d index share a prefix. t.drop(); -t.ensureIndex({"a.b": "2d", "a.c": 1}); +t.createIndex({"a.b": "2d", "a.c": 1}); t.insert({_id: 0, a: [{b: [0, 0]}, {c: 0}]}); t.insert({_id: 1, a: [{b: [1, 1]}, {c: 1}]}); t.insert({_id: 2, a: [{b: [2, 2]}, {c: 2}]}); diff --git a/jstests/core/ne1.js b/jstests/core/ne1.js index 2128bd3a936..5069637eb30 100644 --- a/jstests/core/ne1.js +++ b/jstests/core/ne1.js @@ -6,5 +6,5 @@ t.save({x: 2}); t.save({x: 3}); assert.eq(2, t.find({x: {$ne: 2}}).itcount(), "A"); -t.ensureIndex({x: 1}); +t.createIndex({x: 1}); assert.eq(2, t.find({x: {$ne: 2}}).itcount(), "B"); diff --git a/jstests/core/ne2.js b/jstests/core/ne2.js index db2ee7b01e5..5fef4f1d630 100644 --- a/jstests/core/ne2.js +++ b/jstests/core/ne2.js @@ -5,7 +5,7 @@ t = db.jstests_ne2; t.drop(); -t.ensureIndex({a: 1}); +t.createIndex({a: 1}); t.save({a: -0.5}); t.save({a: 0}); diff --git a/jstests/core/nestedarr1.js b/jstests/core/nestedarr1.js index 7edef9db512..248a70b5f78 100644 --- a/jstests/core/nestedarr1.js +++ b/jstests/core/nestedarr1.js @@ -21,7 +21,7 @@ function makeNestArr(depth) { let collection = db.arrNestTest; collection.drop(); -assert.commandWorked(collection.ensureIndex({a: 1})); +assert.commandWorked(collection.createIndex({a: 1})); const kMaxDocumentDepthSoftLimit = 100; const kJavaScriptMaxDepthLimit = 150; diff --git a/jstests/core/nestedobj1.js b/jstests/core/nestedobj1.js index 44fdd4599d7..ba97f326934 100644 --- a/jstests/core/nestedobj1.js +++ b/jstests/core/nestedobj1.js @@ -19,7 +19,7 @@ function makeNestObj(depth) { let collection = db.objNestTest; collection.drop(); -assert.commandWorked(collection.ensureIndex({a: 1})); +assert.commandWorked(collection.createIndex({a: 1})); const kMaxDocumentDepthSoftLimit = 100; const kJavaScriptMaxDepthLimit = 150; diff --git a/jstests/core/nin.js b/jstests/core/nin.js index d8a254357ba..b9887e48828 100644 --- a/jstests/core/nin.js +++ b/jstests/core/nin.js @@ -57,5 +57,5 @@ doTest = function(n) { doTest("no index"); t.drop(); -t.ensureIndex({a: 1}); +t.createIndex({a: 1}); doTest("with index"); diff --git a/jstests/core/not1.js b/jstests/core/not1.js index 1039ae7c910..0726895ebbd 100644 --- a/jstests/core/not1.js +++ b/jstests/core/not1.js @@ -16,5 +16,5 @@ function test(name) { } test("no index"); -t.ensureIndex({a: 1}); +t.createIndex({a: 1}); test("with index"); diff --git a/jstests/core/not2.js b/jstests/core/not2.js index 0cd9209ce2d..31b2efcfa02 100644 --- a/jstests/core/not2.js +++ b/jstests/core/not2.js @@ -86,6 +86,6 @@ function doTest() { doTest(); // Run the test with an index present. -assert.commandWorked(coll.ensureIndex({i: 1})); +assert.commandWorked(coll.createIndex({i: 1})); doTest(); }()); diff --git a/jstests/core/not3.js b/jstests/core/not3.js index 9f3014f2c1a..eac6bf8f047 100644 --- a/jstests/core/not3.js +++ b/jstests/core/not3.js @@ -4,7 +4,7 @@ var t = db.jstests_not3; t.drop(); -t.ensureIndex({arr: 1}); +t.createIndex({arr: 1}); t.save({_id: 0, arr: [1, 2, 3]}); t.save({_id: 1, arr: [10, 11]}); diff --git a/jstests/core/notablescan.js b/jstests/core/notablescan.js index eca1bd2e787..adad7f1b725 100644 --- a/jstests/core/notablescan.js +++ b/jstests/core/notablescan.js @@ -44,7 +44,7 @@ try { assert.includes(err.toString(), "hint $natural is not allowed, because 'notablescan' is enabled"); - t.ensureIndex({a: 1}); + t.createIndex({a: 1}); assert.eq(0, t.find({a: 1, b: 1}).itcount()); assert.eq(1, t.find({a: 1, b: null}).itcount()); diff --git a/jstests/core/numberlong2.js b/jstests/core/numberlong2.js index 4eadb744131..dad87fe30aa 100644 --- a/jstests/core/numberlong2.js +++ b/jstests/core/numberlong2.js @@ -8,7 +8,7 @@ t = db.jstests_numberlong2; t.drop(); -t.ensureIndex({x: 1}); +t.createIndex({x: 1}); function chk(longNum) { t.remove({}); diff --git a/jstests/core/numberlong4.js b/jstests/core/numberlong4.js index f81a9599e21..d7d73898b34 100644 --- a/jstests/core/numberlong4.js +++ b/jstests/core/numberlong4.js @@ -6,7 +6,7 @@ t.drop(); if (0) { // SERVER-3719 - t.ensureIndex({x: 1}); + t.createIndex({x: 1}); Random.setRandomSeed(); diff --git a/jstests/core/or1.js b/jstests/core/or1.js index c5975a058f2..d90947d5f87 100644 --- a/jstests/core/or1.js +++ b/jstests/core/or1.js @@ -61,13 +61,13 @@ doTest(); // not part of SERVER-1003, but good check for subseq. implementations t.drop(); -t.ensureIndex({a: 1}); +t.createIndex({a: 1}); doTest(); t.drop(); -t.ensureIndex({b: 1}); +t.createIndex({b: 1}); doTest(); t.drop(); -t.ensureIndex({a: 1, b: 1}); +t.createIndex({a: 1, b: 1}); doTest(); diff --git a/jstests/core/or2.js b/jstests/core/or2.js index 5b520197eba..508b3294931 100644 --- a/jstests/core/or2.js +++ b/jstests/core/or2.js @@ -72,17 +72,17 @@ doTest = function(index) { doTest(false); -t.ensureIndex({x: 1}); +t.createIndex({x: 1}); doTest(); t.drop(); -t.ensureIndex({x: 1, a: 1}); +t.createIndex({x: 1, a: 1}); doTest(); t.drop(); -t.ensureIndex({x: 1, b: 1}); +t.createIndex({x: 1, b: 1}); doTest(); t.drop(); -t.ensureIndex({x: 1, a: 1, b: 1}); +t.createIndex({x: 1, a: 1, b: 1}); doTest(); diff --git a/jstests/core/or3.js b/jstests/core/or3.js index 22a26d571ca..26628927c87 100644 --- a/jstests/core/or3.js +++ b/jstests/core/or3.js @@ -63,17 +63,17 @@ doTest = function(index) { doTest(false); -t.ensureIndex({x: 1}); +t.createIndex({x: 1}); doTest(); t.drop(); -t.ensureIndex({x: 1, a: 1}); +t.createIndex({x: 1, a: 1}); doTest(); t.drop(); -t.ensureIndex({x: 1, b: 1}); +t.createIndex({x: 1, b: 1}); doTest(); t.drop(); -t.ensureIndex({x: 1, a: 1, b: 1}); +t.createIndex({x: 1, a: 1, b: 1}); doTest(); diff --git a/jstests/core/or4.js b/jstests/core/or4.js index f065ccbec86..e095eb9961c 100644 --- a/jstests/core/or4.js +++ b/jstests/core/or4.js @@ -14,8 +14,8 @@ const coll = db.or4; coll.drop(); db.getCollection("mrOutput").drop(); -coll.ensureIndex({a: 1}); -coll.ensureIndex({b: 1}); +coll.createIndex({a: 1}); +coll.createIndex({b: 1}); assert.commandWorked(coll.insert({a: 2})); assert.commandWorked(coll.insert({b: 3})); diff --git a/jstests/core/or5.js b/jstests/core/or5.js index 40d7792eeeb..eed4c3fc62d 100644 --- a/jstests/core/or5.js +++ b/jstests/core/or5.js @@ -6,10 +6,10 @@ t = db.jstests_or5; t.drop(); -t.ensureIndex({a: 1}); -t.ensureIndex({b: 1}); +t.createIndex({a: 1}); +t.createIndex({b: 1}); -t.ensureIndex({c: 1}); +t.createIndex({c: 1}); t.save({a: 2}); t.save({b: 3}); @@ -36,7 +36,7 @@ for (i = 2; i <= 7; ++i) { assert.eq.automsg("6", "t.find( {$or:[{a:2},{b:3},{c:6}]} ).batchSize( i ).toArray().length"); } -t.ensureIndex({z: "2d"}); +t.createIndex({z: "2d"}); assert.throws.automsg(function() { return t.find({$or: [{z: {$near: [50, 50]}}, {a: 2}]}).toArray(); @@ -45,9 +45,9 @@ assert.throws.automsg(function() { function reset() { t.drop(); - t.ensureIndex({a: 1}); - t.ensureIndex({b: 1}); - t.ensureIndex({c: 1}); + t.createIndex({a: 1}); + t.createIndex({b: 1}); + t.createIndex({c: 1}); t.save({a: 2}); t.save({a: 2}); diff --git a/jstests/core/or6.js b/jstests/core/or6.js index 144f9ed7e9e..7b18e1c219a 100644 --- a/jstests/core/or6.js +++ b/jstests/core/or6.js @@ -6,8 +6,8 @@ var t = db.jstests_orq; t.drop(); -t.ensureIndex({a: 1, c: 1}); -t.ensureIndex({b: 1, c: 1}); +t.createIndex({a: 1, c: 1}); +t.createIndex({b: 1, c: 1}); t.save({a: 1, c: 9}); t.save({a: 1, c: 10}); diff --git a/jstests/core/or7.js b/jstests/core/or7.js index d824a90aa81..e639a195739 100644 --- a/jstests/core/or7.js +++ b/jstests/core/or7.js @@ -3,7 +3,7 @@ t = db.jstests_or7; t.drop(); -t.ensureIndex({a: 1}); +t.createIndex({a: 1}); t.save({a: 2}); assert.eq.automsg("1", "t.count( {$or:[{a:{$in:[1,3]}},{a:2}]} )"); diff --git a/jstests/core/or8.js b/jstests/core/or8.js index 41537dbdf83..4af81ec4829 100644 --- a/jstests/core/or8.js +++ b/jstests/core/or8.js @@ -14,7 +14,7 @@ t.find({"$or": [{"PropA": {"$lt": "b"}}, {"PropA": {"$lt": "b", "$gt": "a"}}]}). t.save({a: 1}); t.save({a: 3}); -t.ensureIndex({a: 1}); +t.createIndex({a: 1}); t.find({$or: [{a: {$in: []}}]}).toArray(); assert.eq.automsg("2", "t.find({ $or: [ { a: {$in:[]} }, {a:1}, {a:3} ] } ).toArray().length"); assert.eq.automsg("2", "t.find({ $or: [ {a:1}, { a: {$in:[]} }, {a:3} ] } ).toArray().length"); @@ -24,8 +24,8 @@ assert.eq.automsg("2", "t.find({ $or: [ {a:1}, {a:3}, { a: {$in:[]} } ] } ).toAr t.drop(); t.save({a: {b: 1, c: 1}}); -t.ensureIndex({'a.b': 1}); -t.ensureIndex({'a.c': 1}); +t.createIndex({'a.b': 1}); +t.createIndex({'a.c': 1}); assert.eq(1, t.find({$or: [{'a.b': 1}, {'a.c': 1}]}).itcount()); t.remove({}); diff --git a/jstests/core/or9.js b/jstests/core/or9.js index 68814c684cb..4938e84ca04 100644 --- a/jstests/core/or9.js +++ b/jstests/core/or9.js @@ -5,7 +5,7 @@ t = db.jstests_or9; t.drop(); -t.ensureIndex({a: 1, b: 1}); +t.createIndex({a: 1, b: 1}); t.save({a: 2, b: 2}); diff --git a/jstests/core/or_inexact.js b/jstests/core/or_inexact.js index d6a51d66259..0584be98d6d 100644 --- a/jstests/core/or_inexact.js +++ b/jstests/core/or_inexact.js @@ -20,7 +20,7 @@ var cursor; // Case 1: An EXACT predicate and an INEXACT_COVERED t.drop(); -t.ensureIndex({name: 1}); +t.createIndex({name: 1}); t.insert({_id: 0, name: "thomas"}); t.insert({_id: 1, name: "alexandra"}); cursor = t.find({$or: [{name: "thomas"}, {name: /^alexand(er|ra)/}]}); @@ -28,7 +28,7 @@ assert.eq(2, cursor.itcount(), "case 1"); // Case 2: Two INEXACT_COVERED predicates. t.drop(); -t.ensureIndex({name: 1}); +t.createIndex({name: 1}); t.insert({_id: 0, name: "thomas"}); t.insert({_id: 1, name: "alexandra"}); cursor = t.find({$or: [{name: /omas/}, {name: /^alexand(er|ra)/}]}); @@ -36,7 +36,7 @@ assert.eq(2, cursor.itcount(), "case 2"); // Case 3: An EXACT, and INEXACT_COVERED, and an INEXACT_FETCH. t.drop(); -t.ensureIndex({names: 1}); +t.createIndex({names: 1}); t.insert({_id: 0, names: ["thomas", "alexandra"]}); t.insert({_id: 1, names: "frank"}); t.insert({_id: 2, names: "alice"}); @@ -47,7 +47,7 @@ assert.eq(3, cursor.itcount(), "case 3"); // Case 4: Two INEXACT_FETCH. t.drop(); -t.ensureIndex({names: 1}); +t.createIndex({names: 1}); t.insert({_id: 0, names: ["thomas", "alexandra"]}); t.insert({_id: 1, names: ["frank", "alice"]}); t.insert({_id: 2, names: "frank"}); @@ -58,8 +58,8 @@ assert.eq(2, cursor.itcount(), "case 4"); // Case 5: Two indices. One has EXACT and INEXACT_COVERED. The other // has EXACT and INEXACT_FETCH. t.drop(); -t.ensureIndex({first: 1}); -t.ensureIndex({last: 1}); +t.createIndex({first: 1}); +t.createIndex({last: 1}); t.insert({_id: 0, first: "frank", last: "smith"}); t.insert({_id: 1, first: "john", last: "doe"}); t.insert({_id: 2, first: "dave", last: "st"}); @@ -71,7 +71,7 @@ assert.eq(4, cursor.itcount(), "case 5"); // Case 6: Multikey with only EXACT predicates. t.drop(); -t.ensureIndex({names: 1}); +t.createIndex({names: 1}); t.insert({_id: 0, names: ["david", "dave"]}); t.insert({_id: 1, names: ["joseph", "joe", "joey"]}); cursor = t.find({$or: [{names: "dave"}, {names: "joe"}]}); @@ -79,7 +79,7 @@ assert.eq(2, cursor.itcount(), "case 6"); // Case 7: Multikey with EXACT and INEXACT_COVERED. t.drop(); -t.ensureIndex({names: 1}); +t.createIndex({names: 1}); t.insert({_id: 0, names: ["david", "dave"]}); t.insert({_id: 1, names: ["joseph", "joe", "joey"]}); cursor = t.find({$or: [{names: "dave"}, {names: /joe/}]}); @@ -87,8 +87,8 @@ assert.eq(2, cursor.itcount(), "case 7"); // Case 8: Text with EXACT. t.drop(); -t.ensureIndex({pre: 1, names: "text"}); -t.ensureIndex({other: 1}); +t.createIndex({pre: 1, names: "text"}); +t.createIndex({other: 1}); t.insert({_id: 0, pre: 3, names: "david dave", other: 1}); t.insert({_id: 1, pre: 4, names: "joseph joe joey", other: 2}); cursor = t.find({$or: [{$text: {$search: "dave"}, pre: 3}, {other: 2}]}); @@ -96,8 +96,8 @@ assert.eq(2, cursor.itcount(), "case 8"); // Case 9: Text with INEXACT_COVERED. t.drop(); -t.ensureIndex({pre: 1, names: "text"}); -t.ensureIndex({other: 1}); +t.createIndex({pre: 1, names: "text"}); +t.createIndex({other: 1}); t.insert({_id: 0, pre: 3, names: "david dave", other: "foo"}); t.insert({_id: 1, pre: 5, names: "david dave", other: "foo"}); t.insert({_id: 2, pre: 4, names: "joseph joe joey", other: "bar"}); @@ -106,8 +106,8 @@ assert.eq(2, cursor.itcount(), "case 9"); // Case 10: Text requiring filter with INEXACT_COVERED. t.drop(); -t.ensureIndex({pre: 1, names: "text"}); -t.ensureIndex({other: 1}); +t.createIndex({pre: 1, names: "text"}); +t.createIndex({other: 1}); t.insert({_id: 0, pre: 3, names: "david dave", other: "foo"}); t.insert({_id: 1, pre: 3, names: "david dave", other: "foo"}); t.insert({_id: 2, pre: 4, names: "joseph joe joey", other: "bar"}); @@ -116,7 +116,7 @@ assert.eq(3, cursor.itcount(), "case 10"); // Case 11: GEO with non-geo, same index, 2dsphere. t.drop(); -t.ensureIndex({pre: 1, loc: "2dsphere"}); +t.createIndex({pre: 1, loc: "2dsphere"}); t.insert({_id: 0, pre: 3, loc: {type: "Point", coordinates: [40, 5]}}); t.insert({_id: 1, pre: 4, loc: {type: "Point", coordinates: [0, 0]}}); cursor = t.find({ @@ -149,7 +149,7 @@ assert.eq(2, cursor.itcount(), "case 11"); // Case 12: GEO with non-geo, same index, 2d. t.drop(); -t.ensureIndex({pre: 1, loc: "2d"}); +t.createIndex({pre: 1, loc: "2d"}); t.insert({_id: 0, pre: 3, loc: {type: "Point", coordinates: [40, 5]}}); t.insert({_id: 1, pre: 4, loc: {type: "Point", coordinates: [0, 0]}}); cursor = t.find({ @@ -182,7 +182,7 @@ assert.eq(2, cursor.itcount(), "case 12"); // Case 13: $elemMatch object. t.drop(); -t.ensureIndex({"a.b": 1}); +t.createIndex({"a.b": 1}); t.insert({_id: 0, a: [{b: 1}, {b: 2}]}); t.insert({_id: 1, a: [{b: 3}, {b: 4}]}); cursor = t.find({$or: [{a: {$elemMatch: {b: {$lte: 1}}}}, {a: {$elemMatch: {b: {$gte: 4}}}}]}); @@ -190,7 +190,7 @@ assert.eq(2, cursor.itcount(), "case 13"); // Case 14: $elemMatch object, below an AND. t.drop(); -t.ensureIndex({"a.b": 1}); +t.createIndex({"a.b": 1}); t.insert({_id: 0, a: [{b: 1}, {b: 2}]}); t.insert({_id: 1, a: [{b: 2}, {b: 4}]}); cursor = @@ -199,7 +199,7 @@ assert.eq(2, cursor.itcount(), "case 14"); // Case 15: $or below $elemMatch. t.drop(); -t.ensureIndex({"a.b": 1}); +t.createIndex({"a.b": 1}); t.insert({_id: 0, a: [{b: 1}, {b: 2}]}); t.insert({_id: 1, a: [{b: 2}, {b: 4}]}); t.insert({_id: 2, a: {b: 4}}); @@ -208,7 +208,7 @@ assert.eq(2, cursor.itcount(), "case 15"); // Case 16: $or below $elemMatch with INEXACT_COVERED. t.drop(); -t.ensureIndex({"a.b": 1}); +t.createIndex({"a.b": 1}); t.insert({_id: 0, a: [{b: "x"}, {b: "y"}]}); t.insert({_id: 1, a: [{b: "y"}, {b: ["y", "z"]}]}); t.insert({_id: 2, a: {b: ["y", "z"]}}); @@ -217,7 +217,7 @@ assert.eq(2, cursor.itcount(), "case 16"); // Case 17: case from SERVER-14030. t.drop(); -t.ensureIndex({number: 1}); +t.createIndex({number: 1}); t.insert({number: null, user_id: 1}); t.insert({number: 2, user_id: 1}); t.insert({number: 1, user_id: 1}); @@ -226,7 +226,7 @@ assert.eq(3, cursor.itcount(), "case 17"); // Case 18: $in with EXACT and INEXACT_COVERED. t.drop(); -t.ensureIndex({name: 1}); +t.createIndex({name: 1}); t.insert({_id: 0, name: "thomas"}); t.insert({_id: 1, name: "alexandra"}); cursor = t.find({name: {$in: ["thomas", /^alexand(er|ra)/]}}); @@ -234,7 +234,7 @@ assert.eq(2, cursor.itcount(), "case 18"); // Case 19: $in with EXACT, INEXACT_COVERED, and INEXACT_FETCH. t.drop(); -t.ensureIndex({name: 1}); +t.createIndex({name: 1}); t.insert({_id: 0, name: "thomas"}); t.insert({_id: 1, name: "alexandra"}); t.insert({_id: 2}); @@ -243,8 +243,8 @@ assert.eq(3, cursor.itcount(), "case 19"); // Case 20: $in with EXACT, INEXACT_COVERED, and INEXACT_FETCH, two indices. t.drop(); -t.ensureIndex({a: 1}); -t.ensureIndex({b: 1}); +t.createIndex({a: 1}); +t.createIndex({b: 1}); t.insert({_id: 0, a: "x", b: "y"}); t.insert({_id: 1, a: "z", b: "z"}); t.insert({_id: 2}); @@ -256,7 +256,7 @@ assert.eq(5, cursor.itcount(), "case 19"); // Case 21: two $geoWithin that collapse to a single GEO index scan. t.drop(); -t.ensureIndex({loc: "2dsphere"}); +t.createIndex({loc: "2dsphere"}); t.insert({_id: 0, loc: {type: "Point", coordinates: [40, 5]}}); t.insert({_id: 1, loc: {type: "Point", coordinates: [0, 0]}}); cursor = t.find({ diff --git a/jstests/core/ora.js b/jstests/core/ora.js index 06d8f39c48f..ca07516cae3 100644 --- a/jstests/core/ora.js +++ b/jstests/core/ora.js @@ -19,7 +19,7 @@ assert.eq.automsg("10", "t.find({$or: [{$where: 'this.x === 2'}, {x: {$ne: 2}}]} // geo t.drop(); -t.ensureIndex({loc: "2d"}); +t.createIndex({loc: "2d"}); assert.throws(function() { t.find({$or: [{loc: {$near: [11, 11]}}]}).limit(1).next(); diff --git a/jstests/core/orb.js b/jstests/core/orb.js index 345ac92d26e..aa75bb97e0b 100644 --- a/jstests/core/orb.js +++ b/jstests/core/orb.js @@ -4,14 +4,14 @@ var t = db.jstests_orb; t.drop(); t.save({a: 1}); -t.ensureIndex({a: -1}); +t.createIndex({a: -1}); assert.eq.automsg("1", "t.count( {$or: [ { a: { $gt:0,$lt:2 } }, { a: { $gt:-1,$lt:3 } } ] } )"); t.drop(); t.save({a: 1, b: 1}); -t.ensureIndex({a: 1, b: -1}); +t.createIndex({a: 1, b: -1}); assert.eq.automsg("1", "t.count( {$or: [ { a: { $gt:0,$lt:2 } }, { a: { $gt:-1,$lt:3 } } ] } )"); assert.eq.automsg( diff --git a/jstests/core/orc.js b/jstests/core/orc.js index dc46d6de4ad..001d6f4bc9f 100644 --- a/jstests/core/orc.js +++ b/jstests/core/orc.js @@ -20,7 +20,7 @@ t.drop(); // possible to write a more // robust test. -t.ensureIndex({a: -1, b: 1, c: 1}); +t.createIndex({a: -1, b: 1, c: 1}); // sanity test t.save({a: null, b: 4, c: 4}); diff --git a/jstests/core/ord.js b/jstests/core/ord.js index ddbae540ffc..4a76f831246 100644 --- a/jstests/core/ord.js +++ b/jstests/core/ord.js @@ -16,8 +16,8 @@ load("jstests/libs/fixture_helpers.js"); // For FixtureHelpers. const t = db.jstests_ord; t.drop(); -t.ensureIndex({a: 1}); -t.ensureIndex({b: 1}); +t.createIndex({a: 1}); +t.createIndex({b: 1}); for (let i = 0; i < 80; ++i) { t.save({a: 1}); diff --git a/jstests/core/ore.js b/jstests/core/ore.js index 959f43f5101..756db6215c5 100644 --- a/jstests/core/ore.js +++ b/jstests/core/ore.js @@ -4,8 +4,8 @@ t = db.jstests_ore; t.drop(); -t.ensureIndex({a: -1}); -t.ensureIndex({b: 1}); +t.createIndex({a: -1}); +t.createIndex({b: 1}); t.save({a: 1, b: 1}); t.save({a: 2, b: 1}); diff --git a/jstests/core/org.js b/jstests/core/org.js index 7479db062e4..0c6808330c8 100644 --- a/jstests/core/org.js +++ b/jstests/core/org.js @@ -5,8 +5,8 @@ t = db.jstests_org; t.drop(); -t.ensureIndex({a: 1}, {sparse: true}); -t.ensureIndex({b: 1}); +t.createIndex({a: 1}, {sparse: true}); +t.createIndex({b: 1}); t.remove({}); t.save({a: 1, b: 2}); diff --git a/jstests/core/orh.js b/jstests/core/orh.js index 1ceed1d501f..91ce121e5a4 100644 --- a/jstests/core/orh.js +++ b/jstests/core/orh.js @@ -5,8 +5,8 @@ t = db.jstests_orh; t.drop(); -t.ensureIndex({a: 1}, {sparse: true}); -t.ensureIndex({b: 1, a: 1}); +t.createIndex({a: 1}, {sparse: true}); +t.createIndex({b: 1, a: 1}); t.remove({}); t.save({b: 2}); diff --git a/jstests/core/orj.js b/jstests/core/orj.js index 0ec304d9e52..deee0c4821c 100644 --- a/jstests/core/orj.js +++ b/jstests/core/orj.js @@ -84,26 +84,26 @@ function check() { check(); -t.ensureIndex({a: 1}); +t.createIndex({a: 1}); check(); t.dropIndexes(); -t.ensureIndex({b: 1}); +t.createIndex({b: 1}); check(); t.dropIndexes(); -t.ensureIndex({a: 1}); -t.ensureIndex({b: 1}); +t.createIndex({a: 1}); +t.createIndex({b: 1}); check(); t.dropIndexes(); -t.ensureIndex({a: 1, b: 1}); +t.createIndex({a: 1, b: 1}); check(); t.dropIndexes(); -t.ensureIndex({a: 1}); -t.ensureIndex({b: 1}); -t.ensureIndex({a: 1, b: 1}); +t.createIndex({a: 1}); +t.createIndex({b: 1}); +t.createIndex({a: 1, b: 1}); check(); function checkHinted(hint) { diff --git a/jstests/core/ork.js b/jstests/core/ork.js index 7f203c74e5f..9079d3819ba 100644 --- a/jstests/core/ork.js +++ b/jstests/core/ork.js @@ -6,7 +6,7 @@ t = db.jstests_ork; t.drop(); -t.ensureIndex({a: 1}); +t.createIndex({a: 1}); t.save({a: [1, 2], b: 5}); t.save({a: [2, 4], b: 5}); diff --git a/jstests/core/oro.js b/jstests/core/oro.js index 80684869f6d..aa884d306c6 100644 --- a/jstests/core/oro.js +++ b/jstests/core/oro.js @@ -13,7 +13,7 @@ orClauses = []; for (idxKey = 'a'; idxKey <= 'aaaaaaaaaa'; idxKey += 'a') { idx = {}; idx[idxKey] = 1; - t.ensureIndex(idx); + t.createIndex(idx); for (i = 0; i < 200; ++i) { t.insert(idx); } diff --git a/jstests/core/orp.js b/jstests/core/orp.js index a706d6f4c1a..a2918fc5a56 100644 --- a/jstests/core/orp.js +++ b/jstests/core/orp.js @@ -4,9 +4,9 @@ t = db.jstests_orp; t.drop(); -t.ensureIndex({a: 1}); -t.ensureIndex({b: 1}); -t.ensureIndex({c: 1}); +t.createIndex({a: 1}); +t.createIndex({b: 1}); +t.createIndex({c: 1}); for (i = 0; i < 200; ++i) { t.save({a: 1, b: 1}); @@ -23,7 +23,7 @@ assert.eq(201, t.count({$or: [{a: 1}, {c: 1}, {b: 1}]})); // Deduping results that would normally be index only matches on overlapping and double scanned $or // field regions. t.drop(); -t.ensureIndex({a: 1, b: 1}); +t.createIndex({a: 1, b: 1}); for (i = 0; i < 16; ++i) { for (j = 0; j < 16; ++j) { t.save({a: i, b: j}); @@ -33,8 +33,8 @@ assert.eq(16 * 16, t.count({$or: [{a: {$gte: 0}, b: {$gte: 0}}, {a: {$lte: 16}, // Deduping results from a clause that completed before the multi cursor takeover. t.drop(); -t.ensureIndex({a: 1}); -t.ensureIndex({b: 1}); +t.createIndex({a: 1}); +t.createIndex({b: 1}); t.save({a: 1, b: 200}); for (i = 0; i < 200; ++i) { t.save({b: i}); diff --git a/jstests/core/profile_list_indexes.js b/jstests/core/profile_list_indexes.js index 359dd9e85cf..92389bf5642 100644 --- a/jstests/core/profile_list_indexes.js +++ b/jstests/core/profile_list_indexes.js @@ -19,7 +19,7 @@ const numIndexes = 5; for (let i = 0; i < numIndexes; ++i) { let indexSpec = {}; indexSpec["fakeField_" + i] = 1; - assert.commandWorked(testColl.ensureIndex(indexSpec)); + assert.commandWorked(testColl.createIndex(indexSpec)); } testDB.setProfilingLevel(2); diff --git a/jstests/core/proj_key1.js b/jstests/core/proj_key1.js index af6d6d9d9fe..51ca23d0c37 100644 --- a/jstests/core/proj_key1.js +++ b/jstests/core/proj_key1.js @@ -13,7 +13,7 @@ for (i = 0; i < 10; i++) { t.insert({a: i, b: i}); } -t.ensureIndex({a: 1}); +t.createIndex({a: 1}); assert.eq(as, t.find({a: {$gte: 0}}, {a: 1, _id: 0}).sort({a: 1}).toArray()); assert.eq(as, t.find({a: {$gte: 0}}, {a: 1, _id: 0}).sort({a: 1}).batchSize(2).toArray()); diff --git a/jstests/core/queryoptimizera.js b/jstests/core/queryoptimizera.js index 5daccbba232..55d0d5c424a 100644 --- a/jstests/core/queryoptimizera.js +++ b/jstests/core/queryoptimizera.js @@ -83,7 +83,7 @@ t.find({_id: 0, a: 0}).itcount(); assertNoNewWarnings(); // Warnings should not be printed when an index is added on _id. -t.ensureIndex({_id: 1}); +t.createIndex({_id: 1}); t.find({_id: 0}).itcount(); assertNoNewWarnings(); diff --git a/jstests/core/record_store_count.js b/jstests/core/record_store_count.js index 89dcf8d4cdc..f89f1cfea17 100644 --- a/jstests/core/record_store_count.js +++ b/jstests/core/record_store_count.js @@ -15,7 +15,7 @@ coll.drop(); assert.commandWorked(coll.insert({x: 0})); assert.commandWorked(coll.insert({x: 1})); -assert.commandWorked(coll.ensureIndex({x: 1})); +assert.commandWorked(coll.createIndex({x: 1})); // // Logically empty predicates should use the record store's count. @@ -78,7 +78,7 @@ const kNewIndexSpec = { x: 1, _id: 1 }; -assert.commandWorked(coll.ensureIndex(kNewIndexSpec)); +assert.commandWorked(coll.createIndex(kNewIndexSpec)); testExplainAndExpectStage({ expectedStages: ["COUNT", "SHARDING_FILTER"], unexpectedStages: ["FETCH"], diff --git a/jstests/core/regex3.js b/jstests/core/regex3.js index 46b18c03028..158d0607647 100644 --- a/jstests/core/regex3.js +++ b/jstests/core/regex3.js @@ -14,7 +14,7 @@ t.save({name: "aaron"}); assert.eq(2, t.find({name: /^e.*/}).itcount(), "no index count"); assert.eq( 4, t.find({name: /^e.*/}).explain(true).executionStats.totalDocsExamined, "no index explain"); -t.ensureIndex({name: 1}); +t.createIndex({name: 1}); assert.eq(2, t.find({name: /^e.*/}).itcount(), "index count"); assert.eq(2, t.find({name: /^e.*/}).explain(true).executionStats.totalKeysExamined, @@ -28,7 +28,7 @@ t.save({name: "ac"}); t.save({name: "c"}); assert.eq(3, t.find({name: /^aa*/}).itcount(), "B ni"); -t.ensureIndex({name: 1}); +t.createIndex({name: 1}); assert.eq(3, t.find({name: /^aa*/}).itcount(), "B i 1"); assert.eq(4, t.find({name: /^aa*/}).explain(true).executionStats.totalKeysExamined, "B i 1 e"); @@ -39,5 +39,5 @@ t.drop(); t.save({name: ""}); assert.eq(1, t.find({name: /^a?/}).itcount(), "C 1"); -t.ensureIndex({name: 1}); +t.createIndex({name: 1}); assert.eq(1, t.find({name: /^a?/}).itcount(), "C 2"); diff --git a/jstests/core/regex4.js b/jstests/core/regex4.js index 4ced6d06924..0e631082352 100644 --- a/jstests/core/regex4.js +++ b/jstests/core/regex4.js @@ -17,7 +17,7 @@ assert.eq( // assert.eq( 2 , t.find( { name : { $ne : /^e.*/ } } ).count() , "no index count ne" ); // // SERVER-251 -t.ensureIndex({name: 1}); +t.createIndex({name: 1}); assert.eq(2, t.find({name: /^e.*/}).count(), "index count"); assert.eq(2, diff --git a/jstests/core/regex5.js b/jstests/core/regex5.js index 69537e149e5..d0836a62686 100644 --- a/jstests/core/regex5.js +++ b/jstests/core/regex5.js @@ -31,7 +31,7 @@ doit = function() { }; doit(); -t.ensureIndex({x: 1}); +t.createIndex({x: 1}); print("now indexed"); doit(); diff --git a/jstests/core/regex6.js b/jstests/core/regex6.js index 7af6c7d8400..f21152d8c55 100644 --- a/jstests/core/regex6.js +++ b/jstests/core/regex6.js @@ -14,7 +14,7 @@ t.save({name: "bob"}); t.save({name: "aaron"}); t.save({name: "[with]some?symbols"}); -t.ensureIndex({name: 1}); +t.createIndex({name: 1}); assert.eq(0, t.find({name: /^\//}).count(), "index count"); assert.eq( diff --git a/jstests/core/regex7.js b/jstests/core/regex7.js index 290cbe387a9..f864f29be8e 100644 --- a/jstests/core/regex7.js +++ b/jstests/core/regex7.js @@ -17,7 +17,7 @@ assert.eq(/^b/, t.findOne({r: /^b/}).r, '3 1 a'); assert.eq(1, t.count({r: /^b/}), '3 2 a'); // with index -t.ensureIndex({r: 1}); +t.createIndex({r: 1}); assert.eq(/^a/, t.findOne({r: /^a/}).r, '1 1 b'); assert.eq(1, t.count({r: /^a/}), '1 2 b'); assert.eq(/^a/i, t.findOne({r: /^a/i}).r, '2 1 b'); diff --git a/jstests/core/regex8.js b/jstests/core/regex8.js index c92e82e4aa6..d65a6836b26 100644 --- a/jstests/core/regex8.js +++ b/jstests/core/regex8.js @@ -20,5 +20,5 @@ function test(msg) { test("A"); -t.ensureIndex({a: 1}); +t.createIndex({a: 1}); test("B"); diff --git a/jstests/core/regex_embed1.js b/jstests/core/regex_embed1.js index baaa8937962..c74ffb4aa32 100644 --- a/jstests/core/regex_embed1.js +++ b/jstests/core/regex_embed1.js @@ -23,5 +23,5 @@ function test(m) { test("A"); -t.ensureIndex({"a.x": 1}); +t.createIndex({"a.x": 1}); test("B"); diff --git a/jstests/core/regexa.js b/jstests/core/regexa.js index b56e2cf405e..694436e87a8 100644 --- a/jstests/core/regexa.js +++ b/jstests/core/regexa.js @@ -13,7 +13,7 @@ function check() { t.save({a: 'a'}); check(); -t.ensureIndex({a: 1}); +t.createIndex({a: 1}); if (1) { // SERVER-3298 check(); } diff --git a/jstests/core/regexc.js b/jstests/core/regexc.js index d7df4f7d574..e9e2ba613aa 100644 --- a/jstests/core/regexc.js +++ b/jstests/core/regexc.js @@ -7,7 +7,7 @@ var t = db.jstests_regexc; // $and using same index twice t.drop(); -t.ensureIndex({a: 1}); +t.createIndex({a: 1}); t.save({a: "0"}); t.save({a: "1"}); t.save({a: "10"}); @@ -15,7 +15,7 @@ assert.eq(1, t.find({$and: [{a: /0/}, {a: /1/}]}).itcount()); // implicit $and using compound index twice t.drop(); -t.ensureIndex({a: 1, b: 1}); +t.createIndex({a: 1, b: 1}); t.save({a: "0", b: "1"}); t.save({a: "10", b: "10"}); t.save({a: "10", b: "2"}); @@ -23,7 +23,7 @@ assert.eq(2, t.find({a: /0/, b: /1/}).itcount()); // $or using same index twice t.drop(); -t.ensureIndex({a: 1}); +t.createIndex({a: 1}); t.save({a: "0"}); t.save({a: "1"}); t.save({a: "2"}); diff --git a/jstests/core/remove.js b/jstests/core/remove.js index 37754c74190..f08792aeca5 100644 --- a/jstests/core/remove.js +++ b/jstests/core/remove.js @@ -6,7 +6,7 @@ t = db.removetest; function f(n, dir) { - t.ensureIndex({x: dir || 1}); + t.createIndex({x: dir || 1}); for (i = 0; i < n; i++) t.save({x: 3, z: "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"}); diff --git a/jstests/core/remove2.js b/jstests/core/remove2.js index d01c1e2e58c..4193b8dd11f 100644 --- a/jstests/core/remove2.js +++ b/jstests/core/remove2.js @@ -38,10 +38,10 @@ f(); t.drop(); g(); -t.ensureIndex({x: 1}); +t.createIndex({x: 1}); t.remove({}); f(); t.drop(); -t.ensureIndex({x: 1}); +t.createIndex({x: 1}); g(); })(); diff --git a/jstests/core/remove6.js b/jstests/core/remove6.js index b91d28fa4e5..f60200a8d81 100644 --- a/jstests/core/remove6.js +++ b/jstests/core/remove6.js @@ -23,7 +23,7 @@ function test(n, idx) { pop(); assert.eq(N, t.count(), n + " A " + idx); if (idx) - t.ensureIndex(idx); + t.createIndex(idx); var res = del(); assert(!res.hasWriteError(), "error deleting: " + res.toString()); assert.eq(0, t.count(), n + " B " + idx); diff --git a/jstests/core/remove7.js b/jstests/core/remove7.js index 4a1548fbce2..9cc86329990 100644 --- a/jstests/core/remove7.js +++ b/jstests/core/remove7.js @@ -18,7 +18,7 @@ for (i = 0; i < 1000; i++) { t.save({tags: getTags()}); } -t.ensureIndex({tags: 1}); +t.createIndex({tags: 1}); for (i = 0; i < 200; i++) { for (var j = 0; j < 10; j++) diff --git a/jstests/core/remove9.js b/jstests/core/remove9.js index dc3f84a9c34..4962dd9a06f 100644 --- a/jstests/core/remove9.js +++ b/jstests/core/remove9.js @@ -13,7 +13,7 @@ const t = db.jstests_remove9; t.drop(); -t.ensureIndex({i: 1}); +t.createIndex({i: 1}); const bulk = t.initializeUnorderedBulkOp(); for (let i = 0; i < 1000; ++i) { diff --git a/jstests/core/removea.js b/jstests/core/removea.js index 2c45ee665f4..9fd489b7005 100644 --- a/jstests/core/removea.js +++ b/jstests/core/removea.js @@ -10,7 +10,7 @@ Random.setRandomSeed(); for (let v = 0; v < 2; ++v) { // Try each index version. t.drop(); - t.ensureIndex({a: 1}, {v: v}); + t.createIndex({a: 1}, {v: v}); const S = 100; const B = 100; for (let x = 0; x < S; x++) { diff --git a/jstests/core/removeb.js b/jstests/core/removeb.js index b81c0818d21..d4ea12aa8f6 100644 --- a/jstests/core/removeb.js +++ b/jstests/core/removeb.js @@ -13,7 +13,7 @@ const t = db.jstests_removeb; t.drop(); -t.ensureIndex({a: 1}); +t.createIndex({a: 1}); // Make the index multikey to trigger cursor dedup checking. t.insert({a: [-1, -2]}); diff --git a/jstests/core/removec.js b/jstests/core/removec.js index 500437e8891..560f7405de3 100644 --- a/jstests/core/removec.js +++ b/jstests/core/removec.js @@ -8,7 +8,7 @@ t = db.jstests_removec; t.drop(); -t.ensureIndex({a: 1}); +t.createIndex({a: 1}); /** @return an array containing a sequence of numbers from i to i + 10. */ function runStartingWith(i) { diff --git a/jstests/core/rename.js b/jstests/core/rename.js index 08d254bbe29..a8d888393b5 100644 --- a/jstests/core/rename.js +++ b/jstests/core/rename.js @@ -12,8 +12,8 @@ c.drop(); a.save({a: 1}); a.save({a: 2}); -a.ensureIndex({a: 1}); -a.ensureIndex({b: 1}); +a.createIndex({a: 1}); +a.createIndex({b: 1}); c.save({a: 100}); assert.commandFailed( diff --git a/jstests/core/rename4.js b/jstests/core/rename4.js index 1ce3b30f177..98a9dd80d11 100644 --- a/jstests/core/rename4.js +++ b/jstests/core/rename4.js @@ -124,7 +124,7 @@ good({a: 1, c: 4}, {$rename: {b: 'c.d'}}, {a: 1, c: 4}); // check index t.drop(); -t.ensureIndex({a: 1}); +t.createIndex({a: 1}); function l(start, mod, query, expected) { t.remove({}); diff --git a/jstests/core/rename5.js b/jstests/core/rename5.js index 357d67fc9ee..3d5646c7ee5 100644 --- a/jstests/core/rename5.js +++ b/jstests/core/rename5.js @@ -5,7 +5,7 @@ t = db.jstests_rename5; t.drop(); -t.ensureIndex({a: 1}); +t.createIndex({a: 1}); t.save({b: 1}); t.update({}, {$rename: {a: 'b'}}); diff --git a/jstests/core/rename6.js b/jstests/core/rename6.js index faa36a448dd..1122623c165 100644 --- a/jstests/core/rename6.js +++ b/jstests/core/rename6.js @@ -17,7 +17,7 @@ const dbd = testDB.getCollection(d); dbc.drop(); dbd.drop(); -dbc.ensureIndex({ +dbc.createIndex({ "name": 1, "date": 1, "time": 1, diff --git a/jstests/core/rename7.js b/jstests/core/rename7.js index 8f209e83acd..a538f36e2dc 100644 --- a/jstests/core/rename7.js +++ b/jstests/core/rename7.js @@ -28,8 +28,8 @@ b.drop(); a.save({a: 1}); a.save({a: 2}); a.save({a: 3}); -a.ensureIndex({a: 1}); -a.ensureIndex({b: 1}); +a.createIndex({a: 1}); +a.createIndex({b: 1}); assert.commandWorked(admin.runCommand({renameCollection: "db_a.rename7", to: "db_b.rename7"})); diff --git a/jstests/core/return_key.js b/jstests/core/return_key.js index 9d30477bd54..96c6284ebf4 100644 --- a/jstests/core/return_key.js +++ b/jstests/core/return_key.js @@ -24,8 +24,8 @@ assert.commandWorked(coll.insert({a: 1, b: 3})); assert.commandWorked(coll.insert({a: 2, b: 2})); assert.commandWorked(coll.insert({a: 3, b: 1})); -assert.commandWorked(coll.ensureIndex({a: 1})); -assert.commandWorked(coll.ensureIndex({b: 1})); +assert.commandWorked(coll.createIndex({a: 1})); +assert.commandWorked(coll.createIndex({b: 1})); // Basic returnKey. results = coll.find().hint({a: 1}).sort({a: 1}).returnKey().toArray(); diff --git a/jstests/core/server14747.js b/jstests/core/server14747.js index f9a650defa4..c792f214259 100644 --- a/jstests/core/server14747.js +++ b/jstests/core/server14747.js @@ -10,8 +10,8 @@ var t = db.jstests_server14747; t.drop(); -t.ensureIndex({a: 1, b: 1}); -t.ensureIndex({a: 1, c: 1}); +t.createIndex({a: 1, b: 1}); +t.createIndex({a: 1, c: 1}); t.insert({a: 1}); for (var i = 0; i < 10; i++) { t.find({a: 1}).explain(true); diff --git a/jstests/core/server14753.js b/jstests/core/server14753.js index e8de183f2d7..4fac2e06485 100644 --- a/jstests/core/server14753.js +++ b/jstests/core/server14753.js @@ -7,8 +7,8 @@ var t = db.jstests_server14753; t.drop(); -t.ensureIndex({a: 1}); -t.ensureIndex({b: 1}); +t.createIndex({a: 1}); +t.createIndex({b: 1}); for (var i = 0; i < 20; i++) { t.insert({b: i}); } diff --git a/jstests/core/server9547.js b/jstests/core/server9547.js index 66b17644e15..5e2d6aba566 100644 --- a/jstests/core/server9547.js +++ b/jstests/core/server9547.js @@ -8,7 +8,7 @@ for (var i = 0; i < 10; i++) { t.save({a: i}); } -t.ensureIndex({a: 1}); +t.createIndex({a: 1}); // note: max() value is exclusive upper bound assert.eq(4, t.find({}).max({a: 4}).hint({a: 1}).toArray().length, "no order"); diff --git a/jstests/core/set_type_change.js b/jstests/core/set_type_change.js index 12035cc39a9..a0976b3ea44 100644 --- a/jstests/core/set_type_change.js +++ b/jstests/core/set_type_change.js @@ -12,7 +12,7 @@ var coll = db.set_type_change; coll.drop(); -assert.commandWorked(coll.ensureIndex({a: 1})); +assert.commandWorked(coll.createIndex({a: 1})); assert.commandWorked(coll.insert({a: 2})); diff --git a/jstests/core/show_record_id.js b/jstests/core/show_record_id.js index d111858bc7d..0f2df332354 100644 --- a/jstests/core/show_record_id.js +++ b/jstests/core/show_record_id.js @@ -25,7 +25,7 @@ t.save({}); checkResults(t.find().batchSize(2).showRecordId().toArray()); // Check with a covered index. -t.ensureIndex({a: 1}); +t.createIndex({a: 1}); checkResults(t.find({}, {_id: 0, a: 1}).hint({a: 1}).showRecordId().toArray()); checkResults(t.find({}, {_id: 0, a: 1}).hint({a: 1}).showRecordId().toArray()); diff --git a/jstests/core/skip1.js b/jstests/core/skip1.js index ae8f589d616..3b99e6b4cdd 100644 --- a/jstests/core/skip1.js +++ b/jstests/core/skip1.js @@ -6,7 +6,7 @@ var t = db.jstests_skip1; if (0) { // SERVER-2845 t.drop(); - t.ensureIndex({a: 1}); + t.createIndex({a: 1}); t.save({a: 5}); t.save({a: 5}); t.save({a: 5}); diff --git a/jstests/core/sort1.js b/jstests/core/sort1.js index 39c8d3d333d..2a11771fd16 100644 --- a/jstests/core/sort1.js +++ b/jstests/core/sort1.js @@ -22,7 +22,7 @@ for (var pass = 0; pass < 2; pass++) { assert(coll.find().sort({x: -1})[1].x == 3); assert.eq(coll.find().sort({x: -1}).skip(0)[0].x, 5); assert.eq(coll.find().sort({x: -1}).skip(1)[0].x, 3); - coll.ensureIndex({x: 1}); + coll.createIndex({x: 1}); } assert(coll.validate().valid); @@ -38,7 +38,7 @@ for (var pass = 0; pass < 2; pass++) { assert.eq("a", coll.find().sort({'x': 1}).next().x, "c.2"); assert.eq("zed", coll.find().sort({'x': -1}).limit(1).next().x, "c.3"); assert.eq("zed", coll.find().sort({'x': -1}).next().x, "c.4"); - coll.ensureIndex({x: 1}); + coll.createIndex({x: 1}); } assert(coll.validate().valid); diff --git a/jstests/core/sort10.js b/jstests/core/sort10.js index 167cf74bbfc..6819c76fa5b 100644 --- a/jstests/core/sort10.js +++ b/jstests/core/sort10.js @@ -11,7 +11,7 @@ function checkSorting1(opts) { var d = new Date(-50); for (var pass = 0; pass < 2; pass++) { assert(t.find().sort({x: 1})[0].x.valueOf() == d.valueOf()); - t.ensureIndex({x: 1}, opts); + t.createIndex({x: 1}, opts); t.insert({x: new Date()}); } } @@ -42,10 +42,10 @@ reverseDates = dates.slice(0).reverse(); checkSorting2(dates, 1); checkSorting2(reverseDates, -1); -t.ensureIndex({x: 1}); +t.createIndex({x: 1}); checkSorting2(dates, 1); checkSorting2(reverseDates, -1); t.dropIndexes(); -t.ensureIndex({x: -1}); +t.createIndex({x: -1}); checkSorting2(dates, 1); checkSorting2(reverseDates, -1); diff --git a/jstests/core/sort2.js b/jstests/core/sort2.js index ca2d3dc80bf..c584dc48114 100644 --- a/jstests/core/sort2.js +++ b/jstests/core/sort2.js @@ -15,7 +15,7 @@ for (var pass = 0; pass < 2; pass++) { assert(res[0].y.a == 2); assert(res[1].y.a == 5); assert(res.length == 4); - t.ensureIndex({"y.a": 1}); + t.createIndex({"y.a": 1}); } assert(t.validate().valid); @@ -31,5 +31,5 @@ for (var pass = 0; pass < 2; pass++) { for (var i = 0; i < good.length; i++) { assert(good[i].toString() == res[i].x.toString()); } - t.ensureIndex({x: 1}); + t.createIndex({x: 1}); } diff --git a/jstests/core/sort4.js b/jstests/core/sort4.js index 0afe2cebe80..e74df1f4bd6 100644 --- a/jstests/core/sort4.js +++ b/jstests/core/sort4.js @@ -36,10 +36,10 @@ nice({name: 1, prename: 1}, "A,AB,AC,BB,BD", "e1"); assert.commandWorked(coll.insert({name: 'C'})); nice({name: 1, prename: 1}, "A,AB,AC,BB,BD,C", "e2"); // SERVER-282 -assert.commandWorked(coll.ensureIndex({name: 1, prename: 1})); +assert.commandWorked(coll.createIndex({name: 1, prename: 1})); nice({name: 1, prename: 1}, "A,AB,AC,BB,BD,C", "e2ia"); // SERVER-282 assert.commandWorked(coll.dropIndexes()); -assert.commandWorked(coll.ensureIndex({name: 1})); +assert.commandWorked(coll.createIndex({name: 1})); nice({name: 1, prename: 1}, "A,AB,AC,BB,BD,C", "e2ib"); // SERVER-282 }()); diff --git a/jstests/core/sort5.js b/jstests/core/sort5.js index 2f604225d7a..be40802ade4 100644 --- a/jstests/core/sort5.js +++ b/jstests/core/sort5.js @@ -16,7 +16,7 @@ assert.eq([4, 2, 3, 1], return z.x; }), "A no index"); -t.ensureIndex({"y.b": 1, "y.a": -1}); +t.createIndex({"y.b": 1, "y.a": -1}); assert.eq([4, 2, 3, 1], t.find().sort({"y.b": 1, "y.a": -1}).map(function(z) { return z.x; @@ -31,7 +31,7 @@ assert.eq([4, 2, 3, 1], return z.x; }), "B no index"); -t.ensureIndex({"y.b": 1, "_id": -1}); +t.createIndex({"y.b": 1, "_id": -1}); assert.eq([4, 2, 3, 1], t.find().sort({"y.b": 1, _id: -1}).map(function(z) { return z.x; diff --git a/jstests/core/sort6.js b/jstests/core/sort6.js index 2373969f7f6..f2658bbcbad 100644 --- a/jstests/core/sort6.js +++ b/jstests/core/sort6.js @@ -16,7 +16,7 @@ t.insert({_id: 3, c: 2}); assert.eq([3, 2, 1], get(-1), "A1"); // SERVER-635 assert.eq([1, 2, 3], get(1), "A2"); -t.ensureIndex({c: 1}); +t.createIndex({c: 1}); assert.eq([3, 2, 1], get(-1), "B1"); assert.eq([1, 2, 3], get(1), "B2"); @@ -31,7 +31,7 @@ t.insert({_id: 3, c: 2}); assert.eq([3, 2, 1], get(-1), "C1"); // SERVER-635 assert.eq([1, 2, 3], get(1), "C2"); -t.ensureIndex({c: 1}); +t.createIndex({c: 1}); assert.eq([3, 2, 1], get(-1), "D1"); assert.eq([1, 2, 3], get(1), "X2"); diff --git a/jstests/core/sort8.js b/jstests/core/sort8.js index 75d393445a7..65dc2c10fc2 100644 --- a/jstests/core/sort8.js +++ b/jstests/core/sort8.js @@ -10,7 +10,7 @@ t.save({a: [1, 10]}); t.save({a: 5}); unindexedForward = t.find().sort({a: 1}).toArray(); unindexedReverse = t.find().sort({a: -1}).toArray(); -t.ensureIndex({a: 1}); +t.createIndex({a: 1}); indexedForward = t.find().sort({a: 1}).hint({a: 1}).toArray(); indexedReverse = t.find().sort({a: -1}).hint({a: 1}).toArray(); @@ -25,7 +25,7 @@ assert.eq([1, 10], unindexedReverse[0].a); t.dropIndexes(); unindexedForward = t.find({a: {$gte: 5}}).sort({a: 1}).toArray(); unindexedReverse = t.find({a: {$lte: 5}}).sort({a: -1}).toArray(); -t.ensureIndex({a: 1}); +t.createIndex({a: 1}); indexedForward = t.find({a: {$gte: 5}}).sort({a: 1}).hint({a: 1}).toArray(); indexedReverse = t.find({a: {$lte: 5}}).sort({a: -1}).hint({a: 1}).toArray(); diff --git a/jstests/core/sort_numeric.js b/jstests/core/sort_numeric.js index df4e914b87b..5ff3e71a066 100644 --- a/jstests/core/sort_numeric.js +++ b/jstests/core/sort_numeric.js @@ -27,7 +27,7 @@ for (var pass = 0; pass < 2; pass++) { assert(t.find({a: 3.0}).count() == 1); assert(t.find({a: 3.0}).length() == 1); - t.ensureIndex({a: 1}); + t.createIndex({a: 1}); } assert(t.validate().valid); diff --git a/jstests/core/sortb.js b/jstests/core/sortb.js index 34fb94951e9..7f24592e84a 100644 --- a/jstests/core/sortb.js +++ b/jstests/core/sortb.js @@ -8,7 +8,7 @@ load("jstests/libs/fixture_helpers.js"); // For FixtureHelpers. const t = db.jstests_sortb; t.drop(); -t.ensureIndex({b: 1}); +t.createIndex({b: 1}); let i; for (i = 0; i < 100; ++i) { diff --git a/jstests/core/sortd.js b/jstests/core/sortd.js index 87c0453cd7a..e18671005e4 100644 --- a/jstests/core/sortd.js +++ b/jstests/core/sortd.js @@ -21,7 +21,7 @@ t.drop(); t.save({a: [1, 2, 3, 4, 5]}); t.save({a: 10}); -t.ensureIndex({a: 1}); +t.createIndex({a: 1}); assert.eq(2, t.find({a: {$gt: 0}}).sort({a: 1}).itcount()); assert.eq(2, t.find({a: {$gt: 0}, b: null}).sort({a: 1}).itcount()); @@ -38,7 +38,7 @@ for (i = 2; i <= 9; ++i) { for (i = 0; i < 30; ++i) { t.save({a: 100}); } -t.ensureIndex({a: 1}); +t.createIndex({a: 1}); checkNumSorted(10, t.find({a: {$gte: 0, $lte: 10}}).sort({a: 1})); checkNumSorted(10, t.find({a: {$gte: 0, $lte: 10}, b: null}).sort({a: 1})); @@ -56,7 +56,7 @@ for (i = 2; i <= 199; ++i) { for (i = 0; i < 30; ++i) { t.save({a: 2000}); } -t.ensureIndex({a: 1}); +t.createIndex({a: 1}); checkNumSorted(200, t.find({a: {$gte: 0, $lte: 200}}).sort({a: 1})); checkNumSorted(200, t.find({a: {$gte: 0, $lte: 200}, b: null}).sort({a: 1})); @@ -69,6 +69,6 @@ t.drop(); for (i = 399; i >= 0; --i) { t.save({a: i}); } -t.ensureIndex({a: 1}); +t.createIndex({a: 1}); checkNumSorted(400, t.find({a: {$gte: 0, $lte: 400}, b: null}).batchSize(50).sort({a: 1})); diff --git a/jstests/core/sortf.js b/jstests/core/sortf.js index 6f34d80a59d..adb54f38b9c 100644 --- a/jstests/core/sortf.js +++ b/jstests/core/sortf.js @@ -9,8 +9,8 @@ t = db.jstests_sortf; t.drop(); -t.ensureIndex({a: 1}); -t.ensureIndex({b: 1}); +t.createIndex({a: 1}); +t.createIndex({b: 1}); for (i = 0; i < 100; ++i) { t.save({a: 0, b: 0}); diff --git a/jstests/core/sortg.js b/jstests/core/sortg.js index 64edbce53d0..bdf44f4db7b 100644 --- a/jstests/core/sortg.js +++ b/jstests/core/sortg.js @@ -47,9 +47,9 @@ noMemoryException({$natural: 1}); assert.eq(1, t.getIndexes().length); -t.ensureIndex({a: 1}); -t.ensureIndex({b: 1}); -t.ensureIndex({c: 1}); +t.createIndex({a: 1}); +t.createIndex({b: 1}); +t.createIndex({c: 1}); assert.eq(4, t.getIndexes().length); diff --git a/jstests/core/sorth.js b/jstests/core/sorth.js index 4b5aa02c281..41563caa205 100644 --- a/jstests/core/sorth.js +++ b/jstests/core/sorth.js @@ -84,7 +84,7 @@ function reset(sort, index) { t.save({a: 2, b: 0}); t.save({a: 2, b: 3}); t.save({a: 2, b: 5}); - t.ensureIndex(index); + t.createIndex(index); _sort = sort; _hint = index; } diff --git a/jstests/core/sorti.js b/jstests/core/sorti.js index b6518818683..e30739b4867 100644 --- a/jstests/core/sorti.js +++ b/jstests/core/sorti.js @@ -20,6 +20,6 @@ function checkBOrder(query) { checkBOrder(t.find().sort({a: 1})); checkBOrder(t.find({}, {_id: 0, b: 1}).sort({a: 1})); -t.ensureIndex({b: 1}); +t.createIndex({b: 1}); checkBOrder(t.find({}, {_id: 0, b: 1}).sort({a: 1})); checkBOrder(t.find({}, {_id: 0, b: 1}).sort({a: 1}).hint({b: 1})); diff --git a/jstests/core/sortj.js b/jstests/core/sortj.js index 58125c2c00c..a4e8dd599d4 100644 --- a/jstests/core/sortj.js +++ b/jstests/core/sortj.js @@ -11,7 +11,7 @@ load("jstests/libs/fixture_helpers.js"); // For FixtureHelpers. const t = db.jstests_sortj; t.drop(); -t.ensureIndex({a: 1}); +t.createIndex({a: 1}); const numShards = FixtureHelpers.numberOfShardsForCollection(t); diff --git a/jstests/core/sortk.js b/jstests/core/sortk.js index e207c8f1f78..f1b055c2bcc 100644 --- a/jstests/core/sortk.js +++ b/jstests/core/sortk.js @@ -23,7 +23,7 @@ function resetCollection() { } resetCollection(); -t.ensureIndex({a: 1, b: 1}); +t.createIndex({a: 1, b: 1}); function simpleQuery(extraFields, sort, hint) { query = {a: {$in: [1, 2]}}; @@ -93,7 +93,7 @@ assert.eq(3, simpleQueryWithLimit(-3).itcount()); // The index ordering is reversed. resetCollection(); -t.ensureIndex({a: 1, b: -1}); +t.createIndex({a: 1, b: -1}); // The sort order is consistent with the index order. assert.eq(5, simpleQuery({}, {b: -1}, {a: 1, b: -1}).limit(-1)[0].b); @@ -103,7 +103,7 @@ assert.eq(0, simpleQuery({}, {b: 1}, {a: 1, b: -1}).limit(-1)[0].b); // An equality constraint precedes the $in constraint. t.drop(); -t.ensureIndex({a: 1, b: 1, c: 1}); +t.createIndex({a: 1, b: 1, c: 1}); t.save({a: 0, b: 0, c: -1}); t.save({a: 0, b: 2, c: 1}); t.save({a: 1, b: 1, c: 1}); diff --git a/jstests/core/splitvector.js b/jstests/core/splitvector.js index da117c7d3ef..73903a45bb9 100644 --- a/jstests/core/splitvector.js +++ b/jstests/core/splitvector.js @@ -111,7 +111,7 @@ assert.eq( // ------------------------- // Case 3: empty collection -f.ensureIndex({x: 1}); +f.createIndex({x: 1}); assert.eq( [], db.runCommand({splitVector: "test.jstests_splitvector", keyPattern: {x: 1}, maxChunkSize: 1}) @@ -122,7 +122,7 @@ assert.eq( // Case 4: uniform collection resetCollection(); -f.ensureIndex({x: 1}); +f.createIndex({x: 1}); var case4 = function() { // Get baseline document size @@ -156,7 +156,7 @@ case4(); // Case 5: limit number of split points resetCollection(); -f.ensureIndex({x: 1}); +f.createIndex({x: 1}); var case5 = function() { // Fill collection and get split vector for 1MB maxChunkSize @@ -180,7 +180,7 @@ case5(); // Case 6: limit number of objects in a chunk resetCollection(); -f.ensureIndex({x: 1}); +f.createIndex({x: 1}); var case6 = function() { // Fill collection and get split vector for 1MB maxChunkSize @@ -205,7 +205,7 @@ case6(); // [1111111111111111,2,3) resetCollection(); -f.ensureIndex({x: 1}); +f.createIndex({x: 1}); var case7 = function() { // Fill collection and get split vector for 1MB maxChunkSize @@ -227,7 +227,7 @@ case7(); // [1, 22222222222222, 3) resetCollection(); -f.ensureIndex({x: 1}); +f.createIndex({x: 1}); var case8 = function() { bulkInsertDocsFixedX(f, 9, filler, 1); @@ -251,7 +251,7 @@ case8(); // resetCollection(); -f.ensureIndex({x: 1}); +f.createIndex({x: 1}); var case9 = function() { f.save({x: 1}); @@ -286,51 +286,51 @@ case9(); // resetCollection(); -f.ensureIndex({x: 1, y: 1}); +f.createIndex({x: 1, y: 1}); case4(); resetCollection(); -f.ensureIndex({x: 1, y: -1, z: 1}); +f.createIndex({x: 1, y: -1, z: 1}); case4(); resetCollection(); -f.ensureIndex({x: 1, y: 1}); +f.createIndex({x: 1, y: 1}); case5(); resetCollection(); -f.ensureIndex({x: 1, y: -1, z: 1}); +f.createIndex({x: 1, y: -1, z: 1}); case5(); resetCollection(); -f.ensureIndex({x: 1, y: 1}); +f.createIndex({x: 1, y: 1}); case6(); resetCollection(); -f.ensureIndex({x: 1, y: -1, z: 1}); +f.createIndex({x: 1, y: -1, z: 1}); case6(); resetCollection(); -f.ensureIndex({x: 1, y: 1}); +f.createIndex({x: 1, y: 1}); case7(); resetCollection(); -f.ensureIndex({x: 1, y: -1, z: 1}); +f.createIndex({x: 1, y: -1, z: 1}); case7(); resetCollection(); -f.ensureIndex({x: 1, y: 1}); +f.createIndex({x: 1, y: 1}); case8(); resetCollection(); -f.ensureIndex({x: 1, y: -1, z: 1}); +f.createIndex({x: 1, y: -1, z: 1}); case8(); resetCollection(); -f.ensureIndex({x: 1, y: 1}); +f.createIndex({x: 1, y: 1}); case9(); resetCollection(); -f.ensureIndex({x: 1, y: -1, z: 1}); +f.createIndex({x: 1, y: -1, z: 1}); case9(); print("PASSED"); diff --git a/jstests/core/stages_and_hash.js b/jstests/core/stages_and_hash.js index aa91f27e542..e5260c6c1b1 100644 --- a/jstests/core/stages_and_hash.js +++ b/jstests/core/stages_and_hash.js @@ -13,9 +13,9 @@ for (var i = 0; i < N; ++i) { t.insert({foo: i, bar: N - i, baz: i}); } -t.ensureIndex({foo: 1}); -t.ensureIndex({bar: 1}); -t.ensureIndex({baz: 1}); +t.createIndex({foo: 1}); +t.createIndex({bar: 1}); +t.createIndex({baz: 1}); // Scan foo <= 20 ixscan1 = { diff --git a/jstests/core/stages_and_sorted.js b/jstests/core/stages_and_sorted.js index 97387d84064..aa4a2fa08c1 100644 --- a/jstests/core/stages_and_sorted.js +++ b/jstests/core/stages_and_sorted.js @@ -23,9 +23,9 @@ for (var i = 0; i < N; ++i) { t.insert({baz: 12}); } -t.ensureIndex({foo: 1}); -t.ensureIndex({bar: 1}); -t.ensureIndex({baz: 1}); +t.createIndex({foo: 1}); +t.createIndex({bar: 1}); +t.createIndex({baz: 1}); // Scan foo == 1 ixscan1 = { diff --git a/jstests/core/stages_fetch.js b/jstests/core/stages_fetch.js index 48d761e53e7..032cc930cf8 100644 --- a/jstests/core/stages_fetch.js +++ b/jstests/core/stages_fetch.js @@ -13,7 +13,7 @@ for (var i = 0; i < N; ++i) { t.insert({foo: i, bar: N - i, baz: i}); } -t.ensureIndex({foo: 1}); +t.createIndex({foo: 1}); // 20 <= foo <= 30 // bar == 25 (not covered, should error.) diff --git a/jstests/core/stages_ixscan.js b/jstests/core/stages_ixscan.js index 78e22e997c4..86184206e33 100644 --- a/jstests/core/stages_ixscan.js +++ b/jstests/core/stages_ixscan.js @@ -13,8 +13,8 @@ for (var i = 0; i < N; ++i) { t.insert({foo: i, bar: N - i, baz: i}); } -t.ensureIndex({foo: 1}); -t.ensureIndex({foo: 1, baz: 1}); +t.createIndex({foo: 1}); +t.createIndex({foo: 1, baz: 1}); // Test that stageDebug fails if neither the keyPattern nor the index name are present. assert.commandFailed(db.runCommand({ diff --git a/jstests/core/stages_limit_skip.js b/jstests/core/stages_limit_skip.js index b2621623260..00ba7aae4f0 100644 --- a/jstests/core/stages_limit_skip.js +++ b/jstests/core/stages_limit_skip.js @@ -13,7 +13,7 @@ for (var i = 0; i < N; ++i) { t.insert({foo: i, bar: N - i, baz: i}); } -t.ensureIndex({foo: 1}); +t.createIndex({foo: 1}); // foo <= 20, decreasing // Limit of 5 results. diff --git a/jstests/core/stages_mergesort.js b/jstests/core/stages_mergesort.js index c4c4125c1f3..6679da3d5a5 100644 --- a/jstests/core/stages_mergesort.js +++ b/jstests/core/stages_mergesort.js @@ -14,8 +14,8 @@ for (var i = 0; i < N; ++i) { t.insert({baz: 1, bar: i}); } -t.ensureIndex({foo: 1, bar: 1}); -t.ensureIndex({baz: 1, bar: 1}); +t.createIndex({foo: 1, bar: 1}); +t.createIndex({baz: 1, bar: 1}); // foo == 1 // We would (internally) use "": MinKey and "": MaxKey for the bar index bounds. diff --git a/jstests/core/stages_or.js b/jstests/core/stages_or.js index 0fd78bdfc5c..d255404a21c 100644 --- a/jstests/core/stages_or.js +++ b/jstests/core/stages_or.js @@ -13,9 +13,9 @@ for (var i = 0; i < N; ++i) { t.insert({foo: i, bar: N - i, baz: i}); } -t.ensureIndex({foo: 1}); -t.ensureIndex({bar: 1}); -t.ensureIndex({baz: 1}); +t.createIndex({foo: 1}); +t.createIndex({bar: 1}); +t.createIndex({baz: 1}); // baz >= 40 ixscan1 = { diff --git a/jstests/core/stages_sort.js b/jstests/core/stages_sort.js index 46b81662100..60f22c680eb 100644 --- a/jstests/core/stages_sort.js +++ b/jstests/core/stages_sort.js @@ -8,7 +8,7 @@ if (false) { t.insert({foo: i, bar: N - i}); } - t.ensureIndex({foo: 1}); + t.createIndex({foo: 1}); // Foo <= 20, descending. ixscan1 = { diff --git a/jstests/core/stages_text.js b/jstests/core/stages_text.js index 50182b04bb4..4b5379a0e4c 100644 --- a/jstests/core/stages_text.js +++ b/jstests/core/stages_text.js @@ -11,7 +11,7 @@ var collname = "stages_text"; t.save({x: "az b x"}); -t.ensureIndex({x: "text"}); +t.createIndex({x: "text"}); // We expect to retrieve 'b' res = db.runCommand({stageDebug: {collection: collname, plan: {text: {args: {search: "b"}}}}}); diff --git a/jstests/core/type1.js b/jstests/core/type1.js index aae040dee90..8066de2a5c4 100644 --- a/jstests/core/type1.js +++ b/jstests/core/type1.js @@ -13,7 +13,7 @@ assert.eq(1, t.find({x: {$type: 1}}).count(), "A2"); assert.eq(3, t.find({x: {$type: 2}}).count(), "A3"); assert.eq(0, t.find({x: {$type: 3}}).count(), "A4"); -t.ensureIndex({x: 1}); +t.createIndex({x: 1}); assert.eq(4, t.find().count(), "B1"); assert.eq(1, t.find({x: {$type: 1}}).count(), "B2"); diff --git a/jstests/core/type2.js b/jstests/core/type2.js index 9c6baa37b94..d93d313d60f 100644 --- a/jstests/core/type2.js +++ b/jstests/core/type2.js @@ -15,5 +15,5 @@ function test() { } test(); -t.ensureIndex({a: 1}); +t.createIndex({a: 1}); test();
\ No newline at end of file diff --git a/jstests/core/type3.js b/jstests/core/type3.js index 6c2c71e2b0c..1b57e9bb989 100644 --- a/jstests/core/type3.js +++ b/jstests/core/type3.js @@ -8,7 +8,7 @@ t = db.jstests_type3; t.drop(); -t.ensureIndex({a: 1}); +t.createIndex({a: 1}); // Type Object t.save({a: {'': ''}}); diff --git a/jstests/core/uniqueness.js b/jstests/core/uniqueness.js index d138f59d0ae..af4dfb1507f 100644 --- a/jstests/core/uniqueness.js +++ b/jstests/core/uniqueness.js @@ -40,7 +40,7 @@ db.jstests_uniqueness2.drop(); db.jstests_uniqueness2.insert({a: 3}); db.jstests_uniqueness2.insert({a: 3}); assert.eq(2, db.jstests_uniqueness2.count()); -res = db.jstests_uniqueness2.ensureIndex({a: 1}, true); +res = db.jstests_uniqueness2.createIndex({a: 1}, true); assert.commandFailed(res); assert(res.errmsg.match(/E11000/)); @@ -49,7 +49,7 @@ db.jstests_uniqueness2.drop(); db.jstests_uniqueness2.insert({a: 3}); db.jstests_uniqueness2.insert({a: 3}); assert.eq(2, db.jstests_uniqueness2.count()); -res = db.jstests_uniqueness2.ensureIndex({a: 1}, {unique: true, background: true}); +res = db.jstests_uniqueness2.createIndex({a: 1}, {unique: true, background: true}); assert.commandFailed(res); assert(res.errmsg.match(/E11000/)); diff --git a/jstests/core/update2.js b/jstests/core/update2.js index 558e3c7f558..080875b50bd 100644 --- a/jstests/core/update2.js +++ b/jstests/core/update2.js @@ -12,7 +12,7 @@ assert.eq(6, f.findOne().a); f.drop(); f.save({a: 4}); -f.ensureIndex({a: 1}); +f.createIndex({a: 1}); f.update({a: 4}, {$inc: {a: 2}}); assert.eq(6, f.findOne().a); diff --git a/jstests/core/update5.js b/jstests/core/update5.js index 7f41096889c..fafc0d72ce0 100644 --- a/jstests/core/update5.js +++ b/jstests/core/update5.js @@ -26,7 +26,7 @@ function go(key) { var ik = {}; for (k in key) ik[k] = 1; - t.ensureIndex(ik); + t.createIndex(ik); t.update(key, {$inc: {n: 1}}, true); check(4, "D"); diff --git a/jstests/core/update7.js b/jstests/core/update7.js index cb15f211d63..30dd79951dc 100644 --- a/jstests/core/update7.js +++ b/jstests/core/update7.js @@ -49,8 +49,8 @@ assert.eq("3,6", s(), "B3"); t.update({b: 3}, {$inc: {x: 1}}, false, true); assert.eq("3,6", s(), "B4"); -t.ensureIndex({a: 1}); -t.ensureIndex({b: 1}); +t.createIndex({a: 1}); +t.createIndex({b: 1}); t.update({a: 1}, {$inc: {x: 1}}, false, true); assert.eq("4,7", s(), "B5"); @@ -91,7 +91,7 @@ t.drop(); t.save({_id: 1, x: 1, a: [1, 2]}); t.save({_id: 2, x: 5, a: [2, 3]}); -t.ensureIndex({a: 1}); +t.createIndex({a: 1}); assert.eq("1,5", s(), "D1"); t.update({a: 1}, {$inc: {x: 1}}, false, true); @@ -134,7 +134,7 @@ t.save({x: 1}); t.save({x: 2}); t.save({x: 3}); -t.ensureIndex({x: 1}); +t.createIndex({x: 1}); assert.eq("1,2,3", s(), "F1"); t.update({x: {$gt: 0}}, {$inc: {x: 5}}, false, true); diff --git a/jstests/core/update_arraymatch4.js b/jstests/core/update_arraymatch4.js index bda7de512b8..3c087e53ca5 100644 --- a/jstests/core/update_arraymatch4.js +++ b/jstests/core/update_arraymatch4.js @@ -17,7 +17,7 @@ x.arr[0] = "A2"; t.update({arr: "A1"}, {$set: {"arr.$": "A2"}}); assert.eq(x, t.findOne(), "A2"); -t.ensureIndex({arr: 1}); +t.createIndex({arr: 1}); x.arr[0] = "A3"; t.update({arr: "A2"}, {$set: {"arr.$": "A3"}}); assert.eq(x, t.findOne(), "A3"); // SERVER-1055 diff --git a/jstests/core/update_arraymatch5.js b/jstests/core/update_arraymatch5.js index eeca2598d1c..4bddcb1ea26 100644 --- a/jstests/core/update_arraymatch5.js +++ b/jstests/core/update_arraymatch5.js @@ -7,7 +7,7 @@ t = db.update_arraymatch5; t.drop(); t.insert({abc: {visible: true}, testarray: [{foobar_id: 316, visible: true, xxx: 1}]}); -t.ensureIndex({'abc.visible': 1, 'testarray.visible': 1, 'testarray.xxx': 1}); +t.createIndex({'abc.visible': 1, 'testarray.visible': 1, 'testarray.xxx': 1}); assert(t.findOne({'abc.visible': true, testarray: {'$elemMatch': {visible: true, xxx: 1}}}), "A1"); assert(t.findOne({testarray: {'$elemMatch': {visible: true, xxx: 1}}}), "A2"); diff --git a/jstests/core/update_arraymatch6.js b/jstests/core/update_arraymatch6.js index ec318370561..1241753b866 100644 --- a/jstests/core/update_arraymatch6.js +++ b/jstests/core/update_arraymatch6.js @@ -16,5 +16,5 @@ function doTest() { doTest(); t.drop(); -t.ensureIndex({'a.id': 1}); +t.createIndex({'a.id': 1}); doTest();
\ No newline at end of file diff --git a/jstests/core/update_arraymatch7.js b/jstests/core/update_arraymatch7.js index 4ee9ed26f7c..cded4ba56f4 100644 --- a/jstests/core/update_arraymatch7.js +++ b/jstests/core/update_arraymatch7.js @@ -20,5 +20,5 @@ function testPositionalInc() { testPositionalInc(); // Now check with a non multikey index. -t.ensureIndex({'a.b': 1}); +t.createIndex({'a.b': 1}); testPositionalInc(); diff --git a/jstests/core/update_arraymatch8.js b/jstests/core/update_arraymatch8.js index 6340acdb2ab..88b9d3374e8 100644 --- a/jstests/core/update_arraymatch8.js +++ b/jstests/core/update_arraymatch8.js @@ -12,7 +12,7 @@ // array.$.name t = db.jstests_update_arraymatch8; t.drop(); -t.ensureIndex({'array.name': 1}); +t.createIndex({'array.name': 1}); t.insert({'array': [{'name': 'old'}]}); assert(t.findOne({'array.name': 'old'})); t.update({'array.name': 'old'}, {$set: {'array.$.name': 'new'}}); @@ -22,7 +22,7 @@ assert(!t.findOne({'array.name': 'old'})); // array.$ (failed in 2.2.2) t = db.jstests_update_arraymatch8; t.drop(); -t.ensureIndex({'array.name': 1}); +t.createIndex({'array.name': 1}); t.insert({'array': [{'name': 'old'}]}); assert(t.findOne({'array.name': 'old'})); t.update({'array.name': 'old'}, {$set: {'array.$': {'name': 'new'}}}); @@ -32,7 +32,7 @@ assert(!t.findOne({'array.name': 'old'})); // array.0.name t = db.jstests_update_arraymatch8; t.drop(); -t.ensureIndex({'array.name': 1}); +t.createIndex({'array.name': 1}); t.insert({'array': [{'name': 'old'}]}); assert(t.findOne({'array.name': 'old'})); t.update({'array.name': 'old'}, {$set: {'array.0.name': 'new'}}); @@ -42,7 +42,7 @@ assert(!t.findOne({'array.name': 'old'})); // array.0 (failed in 2.2.2) t = db.jstests_update_arraymatch8; t.drop(); -t.ensureIndex({'array.name': 1}); +t.createIndex({'array.name': 1}); t.insert({'array': [{'name': 'old'}]}); assert(t.findOne({'array.name': 'old'})); t.update({'array.name': 'old'}, {$set: {'array.0': {'name': 'new'}}}); @@ -56,7 +56,7 @@ arr = new Array(); for (var i = 0; i < 20; i++) { arr.push({'name': 'old'}); } -t.ensureIndex({'array.name': 1}); +t.createIndex({'array.name': 1}); t.insert({_id: 0, 'array': arr}); assert(t.findOne({'array.name': 'old'})); t.update({_id: 0}, {$set: {'array.12.name': 'new'}}); @@ -71,7 +71,7 @@ arr = new Array(); for (var i = 0; i < 20; i++) { arr.push({'name': 'old'}); } -t.ensureIndex({'array.name': 1}); +t.createIndex({'array.name': 1}); t.insert({_id: 0, 'array': arr}); assert(t.findOne({'array.name': 'old'})); t.update({_id: 0}, {$set: {'array.12': {'name': 'new'}}}); @@ -82,7 +82,7 @@ assert(t.findOne({'array.name': 'old'})); // array.$.123a.name t = db.jstests_update_arraymatch8; t.drop(); -t.ensureIndex({'array.123a.name': 1}); +t.createIndex({'array.123a.name': 1}); t.insert({'array': [{'123a': {'name': 'old'}}]}); assert(t.findOne({'array.123a.name': 'old'})); t.update({'array.123a.name': 'old'}, {$set: {'array.$.123a.name': 'new'}}); @@ -92,7 +92,7 @@ assert(!t.findOne({'array.123a.name': 'old'})); // array.$.123a t = db.jstests_update_arraymatch8; t.drop(); -t.ensureIndex({'array.name': 1}); +t.createIndex({'array.name': 1}); t.insert({'array': [{'123a': {'name': 'old'}}]}); assert(t.findOne({'array.123a.name': 'old'})); t.update({'array.123a.name': 'old'}, {$set: {'array.$.123a': {'name': 'new'}}}); @@ -102,7 +102,7 @@ assert(!t.findOne({'array.123a.name': 'old'})); // array.0.123a.name t = db.jstests_update_arraymatch8; t.drop(); -t.ensureIndex({'array.123a.name': 1}); +t.createIndex({'array.123a.name': 1}); t.insert({'array': [{'123a': {'name': 'old'}}]}); assert(t.findOne({'array.123a.name': 'old'})); t.update({'array.123a.name': 'old'}, {$set: {'array.0.123a.name': 'new'}}); @@ -112,7 +112,7 @@ assert(!t.findOne({'array.123a.name': 'old'})); // array.0.123a t = db.jstests_update_arraymatch8; t.drop(); -t.ensureIndex({'array.name': 1}); +t.createIndex({'array.name': 1}); t.insert({'array': [{'123a': {'name': 'old'}}]}); assert(t.findOne({'array.123a.name': 'old'})); t.update({'array.123a.name': 'old'}, {$set: {'array.0.123a': {'name': 'new'}}}); @@ -122,7 +122,7 @@ assert(!t.findOne({'array.123a.name': 'old'})); // a.0.b t = db.jstests_update_arraymatch8; t.drop(); -t.ensureIndex({'a.0.b': 1}); +t.createIndex({'a.0.b': 1}); t.insert({'a': [[{b: 'old'}]]}); assert(t.findOne({'a.0.0.b': 'old'})); assert(t.findOne({'a.0.b': 'old'})); @@ -133,7 +133,7 @@ assert(!t.findOne({'a.0.b': 'old'})); // a.0.b.c t = db.jstests_update_arraymatch8; t.drop(); -t.ensureIndex({'a.0.b.c': 1}); +t.createIndex({'a.0.b.c': 1}); t.insert({'a': [{b: [{c: 'old'}]}]}); assert(t.findOne({'a.0.b.0.c': 'old'})); assert(t.findOne({'a.b.0.c': 'old'})); @@ -146,7 +146,7 @@ assert(!t.findOne({'a.0.b.c': 'old'})); // a.b.$ref t = db.jstests_update_arraymatch8; t.drop(); -t.ensureIndex({'a.b.$ref': 1}); +t.createIndex({'a.b.$ref': 1}); t.insert({'a': [{'b': {'$ref': 'old', '$id': 0}}]}); assert(t.findOne({'a.b.$ref': 'old'})); assert(t.findOne({'a.0.b.$ref': 'old'})); @@ -157,8 +157,8 @@ assert(!t.findOne({'a.b.$ref': 'old'})); // a.b and a-b t = db.jstests_update_arraymatch8; t.drop(); -t.ensureIndex({'a.b': 1}); -t.ensureIndex({'a-b': 1}); +t.createIndex({'a.b': 1}); +t.createIndex({'a-b': 1}); t.insert({'a': {'b': 'old'}}); assert(t.findOne({'a.b': 'old'})); t.update({}, {$set: {'a': {'b': 'new'}}}); diff --git a/jstests/core/update_multi3.js b/jstests/core/update_multi3.js index 0077bfefead..c8a1fa3b11d 100644 --- a/jstests/core/update_multi3.js +++ b/jstests/core/update_multi3.js @@ -6,7 +6,7 @@ function test(useIndex) { t.drop(); if (useIndex) - t.ensureIndex({k: 1}); + t.createIndex({k: 1}); for (i = 0; i < 10; i++) { t.save({_id: i, k: 'x', a: []}); diff --git a/jstests/core/update_multi4.js b/jstests/core/update_multi4.js index d2030c5dc4b..38fd75358f0 100644 --- a/jstests/core/update_multi4.js +++ b/jstests/core/update_multi4.js @@ -7,7 +7,7 @@ for (i = 0; i < 1000; i++) { t.insert({_id: i, k: i % 12, v: "v" + i % 12}); } -t.ensureIndex({k: 1}); +t.createIndex({k: 1}); assert.eq(84, t.count({k: 2, v: "v2"}), "A0"); diff --git a/jstests/core/update_setOnInsert.js b/jstests/core/update_setOnInsert.js index 430f23ce6dd..9457c69f325 100644 --- a/jstests/core/update_setOnInsert.js +++ b/jstests/core/update_setOnInsert.js @@ -5,7 +5,7 @@ var res; function dotest(useIndex) { t.drop(); if (useIndex) { - t.ensureIndex({a: 1}); + t.createIndex({a: 1}); } t.update({_id: 5}, {$inc: {x: 2}, $setOnInsert: {a: 3}}, true); diff --git a/jstests/core/useindexonobjgtlt.js b/jstests/core/useindexonobjgtlt.js index 4d2368f316f..7b393de7c2f 100644 --- a/jstests/core/useindexonobjgtlt.js +++ b/jstests/core/useindexonobjgtlt.js @@ -3,7 +3,7 @@ t = db.factories; t.drop(); t.insert({name: "xyz", metro: {city: "New York", state: "NY"}}); -t.ensureIndex({metro: 1}); +t.createIndex({metro: 1}); assert(db.factories.find().count()); |