diff options
author | Matt Broadstone <mbroadst@mongodb.com> | 2023-05-07 16:15:25 +0000 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2023-05-07 16:55:23 +0000 |
commit | 43b87324302209cbfa240d6c6b520007669e4ea6 (patch) | |
tree | 7039a07f7116ad86df64fd21eee62f84053ba92e /jstests/core | |
parent | 948bf37c910d9911160e3b275d3c51b146a9c923 (diff) | |
download | mongo-43b87324302209cbfa240d6c6b520007669e4ea6.tar.gz |
SERVER-74787 Prepare jstest corpus for implicit strict mode
Diffstat (limited to 'jstests/core')
429 files changed, 1112 insertions, 1372 deletions
diff --git a/jstests/core/administrative/auth1.js b/jstests/core/administrative/auth1.js index 7633644c0da..4b41c7e21bb 100644 --- a/jstests/core/administrative/auth1.js +++ b/jstests/core/administrative/auth1.js @@ -15,7 +15,7 @@ var mydb = db.getSiblingDB('auth1_db'); mydb.dropAllUsers(); -pass = "a" + Math.random(); +let pass = "a" + Math.random(); // print( "password [" + pass + "]" ); mydb.createUser({user: "eliot", pwd: pass, roles: jsTest.basicUserRoles}); @@ -23,7 +23,7 @@ mydb.createUser({user: "eliot", pwd: pass, roles: jsTest.basicUserRoles}); assert(mydb.auth("eliot", pass), "auth failed"); assert(!mydb.auth("eliot", pass + "a"), "auth should have failed"); -pass2 = "b" + Math.random(); +let pass2 = "b" + Math.random(); mydb.changeUserPassword("eliot", pass2); assert(!mydb.auth("eliot", pass), "failed to change password failed"); diff --git a/jstests/core/administrative/auth2.js b/jstests/core/administrative/auth2.js index eb2b47f696f..4851ac10575 100644 --- a/jstests/core/administrative/auth2.js +++ b/jstests/core/administrative/auth2.js @@ -8,7 +8,7 @@ // SERVER-724 db.runCommand({logout: 1}); -x = db.runCommand({logout: 1}); +let x = db.runCommand({logout: 1}); assert.eq(1, x.ok, "A"); x = db.logout(); diff --git a/jstests/core/administrative/check_shard_index.js b/jstests/core/administrative/check_shard_index.js index f6bb9f3ee7a..bf12d6e4417 100644 --- a/jstests/core/administrative/check_shard_index.js +++ b/jstests/core/administrative/check_shard_index.js @@ -11,7 +11,7 @@ // CHECKSHARDINGINDEX TEST UTILS // ------------------------- -f = db.jstests_shardingindex; +let f = db.jstests_shardingindex; f.drop(); // ------------------------- @@ -22,7 +22,8 @@ f.drop(); 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}}); +let res = + db.runCommand({checkShardingIndex: "test.jstests_shardingindex", keyPattern: {x: 1, y: 1}}); assert.eq(true, res.ok, "1a"); f.save({x: 1, y: 1}); diff --git a/jstests/core/administrative/getlog1.js b/jstests/core/administrative/getlog1.js index a5989e87c75..07c623573ef 100644 --- a/jstests/core/administrative/getlog1.js +++ b/jstests/core/administrative/getlog1.js @@ -5,7 +5,7 @@ // to run: // ./mongo jstests/<this-file> -contains = function(arr, obj) { +let contains = function(arr, obj) { var i = arr.length; while (i--) { if (arr[i] === obj) { diff --git a/jstests/core/administrative/profile/profile3.js b/jstests/core/administrative/profile/profile3.js index 68334e72b08..1ab42d62216 100644 --- a/jstests/core/administrative/profile/profile3.js +++ b/jstests/core/administrative/profile/profile3.js @@ -14,10 +14,10 @@ var stddb = db; var db = db.getSiblingDB("profile3"); db.dropAllUsers(); -t = db.profile3; +let t = db.profile3; t.drop(); -profileCursor = function(query) { +let profileCursor = function(query) { print("----"); query = query || {}; Object.extend(query, {user: username + "@" + db.getName()}); @@ -25,7 +25,7 @@ profileCursor = function(query) { }; try { - username = "jstests_profile3_user"; + var username = "jstests_profile3_user"; db.createUser({user: username, pwd: "password", roles: jsTest.basicUserRoles}); db.logout(); diff --git a/jstests/core/administrative/set_param1.js b/jstests/core/administrative/set_param1.js index dfe71da85d2..35eaa68ca44 100644 --- a/jstests/core/administrative/set_param1.js +++ b/jstests/core/administrative/set_param1.js @@ -9,6 +9,7 @@ // # migration hook. // tenant_migration_incompatible, // ] +load("jstests/libs/fixture_helpers.js"); // Tests for accessing logLevel server parameter using getParameter/setParameter commands // and shell helpers. @@ -165,8 +166,7 @@ assert(!result, assert.commandWorked( db.adminCommand({"setParameter": 1, redactEncryptedFields: old.redactEncryptedFields})); -const isMongos = (db.hello().msg === 'isdbgrid'); -if (!isMongos) { +if (!FixtureHelpers.isMongos(db)) { // // oplogFetcherSteadyStateMaxFetcherRestarts // diff --git a/jstests/core/api/apitest_db.js b/jstests/core/api/apitest_db.js index 805e2c8f990..a2f29340088 100644 --- a/jstests/core/api/apitest_db.js +++ b/jstests/core/api/apitest_db.js @@ -8,7 +8,7 @@ assert("test" == db, "wrong database currently not test"); -dd = function(x) { +let dd = function(x) { // print( x ); }; diff --git a/jstests/core/capped/capped.js b/jstests/core/capped/capped.js index 6c62ba75560..1a26f5a1e22 100644 --- a/jstests/core/capped/capped.js +++ b/jstests/core/capped/capped.js @@ -9,7 +9,7 @@ db.jstests_capped.drop(); db.createCollection("jstests_capped", {capped: true, size: 30000}); -t = db.jstests_capped; +let t = db.jstests_capped; assert.eq(1, t.getIndexes().length, "expected a count of one index for new capped collection"); t.save({x: 1}); diff --git a/jstests/core/capped/capped1.js b/jstests/core/capped/capped1.js index df9b12ddf89..5a02fb6c55f 100644 --- a/jstests/core/capped/capped1.js +++ b/jstests/core/capped/capped1.js @@ -6,11 +6,11 @@ * ] */ -t = db.capped1; +let t = db.capped1; t.drop(); db.createCollection("capped1", {capped: true, size: 1024}); -v = t.validate(); +let v = t.validate(); assert(v.valid, "A : " + tojson(v)); // SERVER-485 t.save({x: 1}); diff --git a/jstests/core/capped/capped5.js b/jstests/core/capped/capped5.js index a276baf043d..d2b704c6cb9 100644 --- a/jstests/core/capped/capped5.js +++ b/jstests/core/capped/capped5.js @@ -6,9 +6,9 @@ * ] */ -tn = "capped5"; +let tn = "capped5"; -t = db[tn]; +let t = db[tn]; t.drop(); db.createCollection(tn, {capped: true, size: 1024 * 1024 * 1}); diff --git a/jstests/core/capped/capped_empty.js b/jstests/core/capped/capped_empty.js index e0515967ca8..020be638c61 100644 --- a/jstests/core/capped/capped_empty.js +++ b/jstests/core/capped/capped_empty.js @@ -15,7 +15,7 @@ * ] */ -t = db.capped_empty; +let t = db.capped_empty; t.drop(); db.createCollection(t.getName(), {capped: true, size: 100}); diff --git a/jstests/core/capped/cappeda.js b/jstests/core/capped/cappeda.js index 3ec0074eefe..816f5be4e0d 100644 --- a/jstests/core/capped/cappeda.js +++ b/jstests/core/capped/cappeda.js @@ -6,13 +6,13 @@ * ] */ -t = db.scan_capped_id; +let t = db.scan_capped_id; t.drop(); -x = t.runCommand("create", {capped: true, size: 10000}); +let x = t.runCommand("create", {capped: true, size: 10000}); assert(x.ok); -for (i = 0; i < 100; i++) +for (let i = 0; i < 100; i++) t.insert({_id: i, x: 1}); function q() { diff --git a/jstests/core/commands_namespace_parsing.js b/jstests/core/commands_namespace_parsing.js index d352a0e3576..b48801beef5 100644 --- a/jstests/core/commands_namespace_parsing.js +++ b/jstests/core/commands_namespace_parsing.js @@ -19,6 +19,7 @@ // does_not_support_causal_consistency, // uses_compact, // ] +load("jstests/libs/fixture_helpers.js"); // This file tests that commands namespace parsing rejects embedded null bytes. // Note that for each command, a properly formatted command object must be passed to the helper @@ -63,9 +64,7 @@ function assertFailsWithInvalidNamespacesForField( } } -const hello = db.runCommand("hello"); -assert.commandWorked(hello); -const isMongos = (hello.msg === "isdbgrid"); +const runningOnMongos = FixtureHelpers.isMongos(db); db.commands_namespace_parsing.drop(); assert.commandWorked(db.commands_namespace_parsing.insert({a: 1})); @@ -182,7 +181,7 @@ assertFailsWithInvalidNamespacesForField("collection", isNotFullyQualified, isNotAdminCommand); -if (!isMongos) { +if (!runningOnMongos) { // Test godinsert fails with an invalid collection name. assertFailsWithInvalidNamespacesForField( "godinsert", {godinsert: "", obj: {_id: 1}}, isNotFullyQualified, isNotAdminCommand); @@ -206,13 +205,13 @@ assertFailsWithInvalidNamespacesForField( assertFailsWithInvalidNamespacesForField( "planCacheClear", {planCacheClear: ""}, isNotFullyQualified, isNotAdminCommand); -if (!isMongos) { +if (!runningOnMongos) { // Test cleanupOrphaned fails with an invalid collection name. assertFailsWithInvalidNamespacesForField( "cleanupOrphaned", {cleanupOrphaned: ""}, isFullyQualified, isAdminCommand); } -if (isMongos) { +if (runningOnMongos) { // Test enableSharding fails with an invalid database name. assertFailsWithInvalidNamespacesForField( "enableSharding", {enableSharding: ""}, isNotFullyQualified, isAdminCommand); @@ -266,7 +265,7 @@ assertFailsWithInvalidNamespacesForField( assertFailsWithInvalidNamespacesForField( "create", {create: ""}, isNotFullyQualified, isNotAdminCommand); -if (!isMongos) { +if (!runningOnMongos) { // Test cloneCollectionAsCapped fails with an invalid source collection name. assertFailsWithInvalidNamespacesForField( "cloneCollectionAsCapped", @@ -308,7 +307,7 @@ assertFailsWithInvalidNamespacesForField( assertFailsWithInvalidNamespacesForField( "dropIndexes", {dropIndexes: "", index: "*"}, isNotFullyQualified, isNotAdminCommand); -if (!isMongos) { +if (!runningOnMongos) { // Test compact fails with an invalid collection name. assertFailsWithInvalidNamespacesForField( "compact", {compact: ""}, isNotFullyQualified, isNotAdminCommand); @@ -322,7 +321,7 @@ assertFailsWithInvalidNamespacesForField( isNotAdminCommand); // Test reIndex fails with an invalid collection name. -if (!isMongos) { +if (!runningOnMongos) { assertFailsWithInvalidNamespacesForField( "reIndex", {reIndex: ""}, isNotFullyQualified, isNotAdminCommand); } diff --git a/jstests/core/commands_with_uuid.js b/jstests/core/commands_with_uuid.js index b0260e0bc31..3744e038992 100644 --- a/jstests/core/commands_with_uuid.js +++ b/jstests/core/commands_with_uuid.js @@ -10,6 +10,7 @@ * assumes_no_implicit_index_creation * ] */ +load("jstests/libs/fixture_helpers.js"); (function() { 'use strict'; @@ -29,10 +30,7 @@ if (uuid == null) { } // No support for UUIDs on mongos. -const hello = db.runCommand("hello"); -assert.commandWorked(hello); -const isMongos = (hello.msg === "isdbgrid"); -if (isMongos) { +if (FixtureHelpers.isMongos(db)) { return; } diff --git a/jstests/core/connection_string_validation.js b/jstests/core/connection_string_validation.js index 6236e445a77..43a7373b973 100644 --- a/jstests/core/connection_string_validation.js +++ b/jstests/core/connection_string_validation.js @@ -5,7 +5,7 @@ // ] // Related to SERVER-8030. -port = "27017"; +let port = "27017"; if (db.getMongo().host.indexOf(":") >= 0) { var idx = db.getMongo().host.indexOf(":"); diff --git a/jstests/core/dbcase.js b/jstests/core/dbcase.js index 23b5bccd305..78d6e05f8ab 100644 --- a/jstests/core/dbcase.js +++ b/jstests/core/dbcase.js @@ -5,15 +5,15 @@ // multiple_tenants_incompatible, // ] -a = db.getSiblingDB("dbcasetest_dbnamea"); -b = db.getSiblingDB("dbcasetest_dbnameA"); +let a = db.getSiblingDB("dbcasetest_dbnamea"); +let b = db.getSiblingDB("dbcasetest_dbnameA"); a.dropDatabase(); b.dropDatabase(); assert.commandWorked(a.foo.save({x: 1})); -res = b.foo.save({x: 1}); +let res = b.foo.save({x: 1}); assert.writeError(res); assert.neq(-1, db.getMongo().getDBNames().indexOf(a.getName())); @@ -23,8 +23,8 @@ printjson(db.getMongo().getDBs().databases); a.dropDatabase(); b.dropDatabase(); -ai = db.getMongo().getDBNames().indexOf(a.getName()); -bi = db.getMongo().getDBNames().indexOf(b.getName()); +let ai = db.getMongo().getDBNames().indexOf(a.getName()); +let bi = db.getMongo().getDBNames().indexOf(b.getName()); // One of these dbs may exist if there is a secondary active, but they must // not both exist. assert(ai == -1 || bi == -1); diff --git a/jstests/core/dbhash.js b/jstests/core/dbhash.js index c601c721f5b..33ee736e4b1 100644 --- a/jstests/core/dbhash.js +++ b/jstests/core/dbhash.js @@ -3,15 +3,15 @@ // not_allowed_with_security_token, // ] -a = db.dbhasha; -b = db.dbhashb; +let a = db.dbhasha; +let b = db.dbhashb; a.drop(); b.drop(); // debug SERVER-761 db.getCollectionNames().forEach(function(x) { - v = db[x].validate(); + let v = db[x].validate(); if (!v.valid) { print(x); printjson(v); @@ -45,8 +45,8 @@ assert.neq(gh(a), gh(b), "A2"); b.insert({_id: 5}); assert.eq(gh(a), gh(b), "A3"); -dba = db.getSiblingDB("dbhasha"); -dbb = db.getSiblingDB("dbhashb"); +let dba = db.getSiblingDB("dbhasha"); +let dbb = db.getSiblingDB("dbhashb"); dba.dropDatabase(); dbb.dropDatabase(); diff --git a/jstests/core/dbhash2.js b/jstests/core/dbhash2.js index 93ec2abf99c..cf86a1a6d03 100644 --- a/jstests/core/dbhash2.js +++ b/jstests/core/dbhash2.js @@ -4,20 +4,20 @@ // assumes_superuser_permissions, // ] -mydb = db.getSiblingDB("config"); +let mydb = db.getSiblingDB("config"); -t = mydb.foo; +let t = mydb.foo; t.drop(); assert.commandWorked(t.insert({x: 1})); -res1 = mydb.runCommand("dbhash"); -res2 = mydb.runCommand("dbhash"); +let res1 = mydb.runCommand("dbhash"); +let res2 = mydb.runCommand("dbhash"); assert.commandWorked(res1); assert.commandWorked(res2); assert.eq(res1.collections.foo, res2.collections.foo); assert.commandWorked(t.insert({x: 2})); -res3 = mydb.runCommand("dbhash"); +let res3 = mydb.runCommand("dbhash"); assert.commandWorked(res3); assert.neq(res1.collections.foo, res3.collections.foo); diff --git a/jstests/core/ddl/bad_index_plugin.js b/jstests/core/ddl/bad_index_plugin.js index c9cd549cc03..cb52ef0c1ab 100644 --- a/jstests/core/ddl/bad_index_plugin.js +++ b/jstests/core/ddl/bad_index_plugin.js @@ -1,5 +1,5 @@ // SERVER-5826 ensure you can't build an index with a non-existent plugin -t = db.bad_index_plugin; +let t = db.bad_index_plugin; assert.commandWorked(t.createIndex({good: 1})); assert.eq(t.getIndexes().length, 2); // good + _id diff --git a/jstests/core/ddl/capped_convertToCapped1.js b/jstests/core/ddl/capped_convertToCapped1.js index 137705c8661..4f51edc6c24 100644 --- a/jstests/core/ddl/capped_convertToCapped1.js +++ b/jstests/core/ddl/capped_convertToCapped1.js @@ -17,21 +17,21 @@ * ] */ -source = db.capped_convertToCapped1; -dest = db.capped_convertToCapped1_clone; +let source = db.capped_convertToCapped1; +let dest = db.capped_convertToCapped1_clone; source.drop(); dest.drop(); -N = 1000; +let N = 1000; -for (i = 0; i < N; ++i) { +for (let i = 0; i < N; ++i) { source.save({i: i}); } assert.eq(N, source.count()); // should all fit -res = db.runCommand( +let res = db.runCommand( {cloneCollectionAsCapped: source.getName(), toCollection: dest.getName(), size: 100000}); assert.commandWorked(res); assert.eq(source.count(), dest.count()); diff --git a/jstests/core/ddl/create_indexes.js b/jstests/core/ddl/create_indexes.js index 64598838466..3ab29ffb6a4 100644 --- a/jstests/core/ddl/create_indexes.js +++ b/jstests/core/ddl/create_indexes.js @@ -6,12 +6,13 @@ */ (function() { 'use strict'; +load("jstests/libs/fixture_helpers.js"); const kUnknownIDLFieldError = 40415; -const isMongos = ("isdbgrid" == db.runCommand("hello").msg); +const runningOnMongos = FixtureHelpers.isMongos(db); const extractResult = function(obj) { - if (!isMongos) + if (!runningOnMongos) return obj; // Sample mongos format: diff --git a/jstests/core/ddl/drop3.js b/jstests/core/ddl/drop3.js index 78d4872a6c0..7829b9cf310 100644 --- a/jstests/core/ddl/drop3.js +++ b/jstests/core/ddl/drop3.js @@ -4,8 +4,8 @@ // does_not_support_causal_consistency, // ] -t = db.jstests_drop3; -sub = t.sub; +let t = db.jstests_drop3; +let sub = t.sub; t.drop(); sub.drop(); diff --git a/jstests/core/ddl/drop_index.js b/jstests/core/ddl/drop_index.js index 3f3e815d47d..ed11b3a5e46 100644 --- a/jstests/core/ddl/drop_index.js +++ b/jstests/core/ddl/drop_index.js @@ -3,6 +3,7 @@ // @tags: [assumes_no_implicit_index_creation] (function() { 'use strict'; +load("jstests/libs/fixture_helpers.js"); const t = db.drop_index; t.drop(); @@ -51,7 +52,7 @@ assertIndexes(['b_1', 'c_1', 'd_1', 'e_1'], 'dropping {a: 1} by name'); assert.commandWorked(t.dropIndex({b: 1})); assertIndexes(['c_1', 'd_1', 'e_1'], 'dropping {b: 1} by key pattern'); -const isMongos = assert.commandWorked(db.runCommand("hello")).msg === "isdbgrid"; +const runningOnMongos = FixtureHelpers.isMongos(db); // Not allowed to drop _id index. for (const dropIndexArg of ['_id_', {_id: 1}]) { @@ -59,7 +60,7 @@ for (const dropIndexArg of ['_id_', {_id: 1}]) { jsTestLog(`Reply to dropIndexes with arg ${tojson(dropIndexArg)}: ${tojson(dropIdIndexReply)}`); assert.commandFailedWithCode(dropIdIndexReply, ErrorCodes.InvalidOptions); assert(dropIdIndexReply.hasOwnProperty('errmsg')); - if (isMongos) { + if (runningOnMongos) { assert(dropIdIndexReply.hasOwnProperty('raw')); } } diff --git a/jstests/core/ddl/rename_collection_capped.js b/jstests/core/ddl/rename_collection_capped.js index 670e5ce611b..e0eb2efa9c3 100644 --- a/jstests/core/ddl/rename_collection_capped.js +++ b/jstests/core/ddl/rename_collection_capped.js @@ -13,9 +13,9 @@ * ] */ -a = db.jstests_rename_a; -b = db.jstests_rename_b; -c = db.jstests_rename_c; +let a = db.jstests_rename_a; +let b = db.jstests_rename_b; +let c = db.jstests_rename_c; a.drop(); b.drop(); @@ -26,14 +26,14 @@ c.drop(); // note we use floats to make sure numbers are represented as doubles for SpiderMonkey, since test // relies on record size db.createCollection("jstests_rename_a", {capped: true, size: 10000}); -for (i = 0.1; i < 10; ++i) { +for (let i = 0.1; i < 10; ++i) { a.save({i: i}); } assert.commandWorked( db.adminCommand({renameCollection: "test.jstests_rename_a", to: "test.jstests_rename_b"})); assert.eq(1, b.countDocuments({i: 9.1})); printjson(b.stats()); -for (i = 10.1; i < 1000; ++i) { +for (var i = 10.1; i < 1000; ++i) { b.save({i: i}); } printjson(b.stats()); diff --git a/jstests/core/ddl/rename_collection_staytemp.js b/jstests/core/ddl/rename_collection_staytemp.js index 5db125f1a23..5107b399627 100644 --- a/jstests/core/ddl/rename_collection_staytemp.js +++ b/jstests/core/ddl/rename_collection_staytemp.js @@ -12,8 +12,8 @@ * ] */ -orig = 'rename_stayTemp_orig'; -dest = 'rename_stayTemp_dest'; +let orig = 'rename_stayTemp_orig'; +let dest = 'rename_stayTemp_dest'; db[orig].drop(); db[dest].drop(); diff --git a/jstests/core/delx.js b/jstests/core/delx.js index 331f6a18b67..b78e3051f8f 100644 --- a/jstests/core/delx.js +++ b/jstests/core/delx.js @@ -1,11 +1,11 @@ // @tags: [assumes_against_mongod_not_mongos, requires_getmore, requires_non_retryable_writes] -a = db.getSiblingDB("delxa"); -b = db.getSiblingDB("delxb"); +let a = db.getSiblingDB("delxa"); +let b = db.getSiblingDB("delxb"); function setup(mydb) { mydb.dropDatabase(); - for (i = 0; i < 100; i++) { + for (let i = 0; i < 100; i++) { mydb.foo.insert({_id: i}); } } @@ -16,8 +16,8 @@ setup(b); assert.eq(100, a.foo.find().itcount(), "A1"); assert.eq(100, b.foo.find().itcount(), "A2"); -x = a.foo.find().sort({_id: 1}).batchSize(60); -y = b.foo.find().sort({_id: 1}).batchSize(60); +let x = a.foo.find().sort({_id: 1}).batchSize(60); +let y = b.foo.find().sort({_id: 1}).batchSize(60); x.next(); y.next(); @@ -27,7 +27,7 @@ a.foo.remove({_id: {$gt: 50}}); assert.eq(51, a.foo.find().itcount(), "B1"); assert.eq(100, b.foo.find().itcount(), "B2"); -xCount = x.itcount(); +let xCount = x.itcount(); assert(xCount == 59 || xCount == 99, "C1 : " + xCount); // snapshot or not is ok assert.eq( 99, diff --git a/jstests/core/error5.js b/jstests/core/error5.js index edcfa059d25..fe4efef15e3 100644 --- a/jstests/core/error5.js +++ b/jstests/core/error5.js @@ -1,6 +1,6 @@ // @tags: [requires_fastcount] -t = db.error5; +let t = db.error5; t.drop(); assert.throws(function() { diff --git a/jstests/core/hint1.js b/jstests/core/hint1.js index d584144e641..09d328350c3 100644 --- a/jstests/core/hint1.js +++ b/jstests/core/hint1.js @@ -1,4 +1,4 @@ -p = db.jstests_hint1; +let p = db.jstests_hint1; p.drop(); p.save({ts: new Date(1), cls: "entry", verticals: "alleyinsider", live: true}); diff --git a/jstests/core/id1.js b/jstests/core/id1.js index 79e26e33e90..a3fbaea3bfc 100644 --- a/jstests/core/id1.js +++ b/jstests/core/id1.js @@ -1,6 +1,6 @@ // @tags: [requires_fastcount] -t = db.id1; +let t = db.id1; t.drop(); t.save({_id: {a: 1, b: 2}, x: "a"}); diff --git a/jstests/core/index/covered/coveredIndex3.js b/jstests/core/index/covered/coveredIndex3.js index 8b15b40e862..dd44f2544ea 100644 --- a/jstests/core/index/covered/coveredIndex3.js +++ b/jstests/core/index/covered/coveredIndex3.js @@ -6,8 +6,8 @@ if (0) { // SERVER-4975 - t = db.jstests_coveredIndex3; - t2 = db.jstests_coveredIndex3_other; + let t = db.jstests_coveredIndex3; + let t2 = db.jstests_coveredIndex3_other; t.drop(); t2.drop(); @@ -15,30 +15,30 @@ if (0) { // SERVER-4975 // Insert an array, which will make the { a:1 } index multikey and should disable covered // index // matching. - p1 = startParallelShell( + let p1 = startParallelShell( 'for( i = 0; i < 60; ++i ) { \ db.jstests_coveredIndex3.save( { a:[ 2000, 2001 ] } ); \ sleep( 300 ); \ }'); // Frequent writes cause the find operation to yield. - p2 = startParallelShell( + let p2 = startParallelShell( 'for( i = 0; i < 1800; ++i ) { \ db.jstests_coveredIndex3_other.save( {} ); \ sleep( 10 ); \ }'); - for (i = 0; i < 30; ++i) { + for (let i = 0; i < 30; ++i) { t.drop(); t.createIndex({a: 1}); - for (j = 0; j < 1000; ++j) { + for (let j = 0; j < 1000; ++j) { t.save({a: j}); } - c = t.find({}, {_id: 0, a: 1}).hint({a: 1}).batchSize(batchSize); + let c = t.find({}, {_id: 0, a: 1}).hint({a: 1}).batchSize(batchSize); while (c.hasNext()) { - o = c.next(); + let o = c.next(); // If o contains a high numeric 'a' value, it must come from an array saved in p1. assert(!(o.a > 1500), 'improper object returned ' + tojson(o)); } diff --git a/jstests/core/index/covered/coveredIndex4.js b/jstests/core/index/covered/coveredIndex4.js index 7433ed7b9d6..b415328474e 100644 --- a/jstests/core/index/covered/coveredIndex4.js +++ b/jstests/core/index/covered/coveredIndex4.js @@ -5,14 +5,14 @@ // Test covered index projection with $or clause, specifically in getMore // SERVER-4980 -t = db.jstests_coveredIndex4; +let t = db.jstests_coveredIndex4; t.drop(); t.createIndex({a: 1}); t.createIndex({b: 1}); -orClause = []; -for (i = 0; i < 200; ++i) { +let orClause = []; +for (let i = 0; i < 200; ++i) { if (i % 2 == 0) { t.save({a: i}); orClause.push({a: i}); @@ -22,11 +22,11 @@ for (i = 0; i < 200; ++i) { } } -c = t.find({$or: orClause}, {_id: 0, a: 1}); +let c = t.find({$or: orClause}, {_id: 0, a: 1}); // No odd values of a were saved, so we should not see any in the results. while (c.hasNext()) { - o = c.next(); + let o = c.next(); if (o.a) { assert.eq(0, o.a % 2, 'unexpected result: ' + tojson(o)); } @@ -36,7 +36,7 @@ c = t.find({$or: orClause}, {_id: 0, b: 1}); // No even values of b were saved, so we should not see any in the results. while (c.hasNext()) { - o = c.next(); + let o = c.next(); if (o.b) { assert.eq(1, o.b % 2, 'unexpected result: ' + tojson(o)); } diff --git a/jstests/core/index/covered/covered_index_compound_1.js b/jstests/core/index/covered/covered_index_compound_1.js index 0efff371059..2227803a890 100644 --- a/jstests/core/index/covered/covered_index_compound_1.js +++ b/jstests/core/index/covered/covered_index_compound_1.js @@ -12,7 +12,7 @@ load("jstests/libs/analyze_plan.js"); var coll = db.getCollection("covered_compound_1"); coll.drop(); -for (i = 0; i < 100; i++) { +for (let i = 0; i < 100; i++) { coll.insert({a: i, b: "strvar_" + (i % 13), c: NumberInt(i % 10)}); } coll.createIndex({a: 1, b: -1, c: 1}); diff --git a/jstests/core/index/covered/covered_index_simple_1.js b/jstests/core/index/covered/covered_index_simple_1.js index 16a6e3cdc6a..6b6db4ffe83 100644 --- a/jstests/core/index/covered/covered_index_simple_1.js +++ b/jstests/core/index/covered/covered_index_simple_1.js @@ -12,13 +12,13 @@ load("jstests/libs/analyze_plan.js"); var coll = db.getCollection("covered_simple_1"); coll.drop(); -for (i = 0; i < 10; i++) { +for (let i = 0; i < 10; i++) { coll.insert({foo: i}); } -for (i = 0; i < 10; i++) { +for (let i = 0; i < 10; i++) { coll.insert({foo: i}); } -for (i = 0; i < 5; i++) { +for (let i = 0; i < 5; i++) { coll.insert({bar: i}); } coll.insert({foo: "string"}); diff --git a/jstests/core/index/covered/covered_index_simple_2.js b/jstests/core/index/covered/covered_index_simple_2.js index cf04f940ad0..6022bae3a5f 100644 --- a/jstests/core/index/covered/covered_index_simple_2.js +++ b/jstests/core/index/covered/covered_index_simple_2.js @@ -12,7 +12,7 @@ load("jstests/libs/analyze_plan.js"); var coll = db.getCollection("covered_simple_2"); coll.drop(); -for (i = 0; i < 10; i++) { +for (let i = 0; i < 10; i++) { coll.insert({foo: i}); } coll.insert({foo: "string"}); diff --git a/jstests/core/index/covered/covered_index_simple_3.js b/jstests/core/index/covered/covered_index_simple_3.js index 4beff2b3c5a..5c8402803c1 100644 --- a/jstests/core/index/covered/covered_index_simple_3.js +++ b/jstests/core/index/covered/covered_index_simple_3.js @@ -12,10 +12,10 @@ load("jstests/libs/analyze_plan.js"); var coll = db.getCollection("covered_simple_3"); coll.drop(); -for (i = 0; i < 10; i++) { +for (let i = 0; i < 10; i++) { coll.insert({foo: i}); } -for (i = 0; i < 5; i++) { +for (let i = 0; i < 5; i++) { coll.insert({bar: i}); } coll.insert({foo: "string"}); diff --git a/jstests/core/index/covered/covered_index_simple_id.js b/jstests/core/index/covered/covered_index_simple_id.js index 59efcd7f13a..6fc7279f56d 100644 --- a/jstests/core/index/covered/covered_index_simple_id.js +++ b/jstests/core/index/covered/covered_index_simple_id.js @@ -9,7 +9,7 @@ load("jstests/libs/analyze_plan.js"); var coll = db.getCollection("covered_simple_id"); coll.drop(); -for (i = 0; i < 10; i++) { +for (let i = 0; i < 10; i++) { coll.insert({_id: i}); } coll.insert({_id: "string"}); diff --git a/jstests/core/index/covered/covered_index_sort_1.js b/jstests/core/index/covered/covered_index_sort_1.js index 499bff128e7..d1f1803f1e1 100644 --- a/jstests/core/index/covered/covered_index_sort_1.js +++ b/jstests/core/index/covered/covered_index_sort_1.js @@ -12,13 +12,13 @@ load("jstests/libs/analyze_plan.js"); var coll = db.getCollection("covered_sort_1"); coll.drop(); -for (i = 0; i < 10; i++) { +for (let i = 0; i < 10; i++) { coll.insert({foo: i}); } -for (i = 0; i < 10; i++) { +for (let i = 0; i < 10; i++) { coll.insert({foo: i}); } -for (i = 0; i < 5; i++) { +for (let i = 0; i < 5; i++) { coll.insert({bar: i}); } coll.insert({foo: "1"}); diff --git a/jstests/core/index/covered/covered_index_sort_2.js b/jstests/core/index/covered/covered_index_sort_2.js index 736a48bb452..4818b325a02 100644 --- a/jstests/core/index/covered/covered_index_sort_2.js +++ b/jstests/core/index/covered/covered_index_sort_2.js @@ -9,7 +9,7 @@ load("jstests/libs/analyze_plan.js"); var coll = db.getCollection("covered_sort_2"); coll.drop(); -for (i = 0; i < 10; i++) { +for (let i = 0; i < 10; i++) { coll.insert({_id: i}); } coll.insert({_id: "1"}); diff --git a/jstests/core/index/covered/covered_index_sort_3.js b/jstests/core/index/covered/covered_index_sort_3.js index 9e57a79a2a2..dc6b2dc25e6 100644 --- a/jstests/core/index/covered/covered_index_sort_3.js +++ b/jstests/core/index/covered/covered_index_sort_3.js @@ -12,7 +12,7 @@ load("jstests/libs/analyze_plan.js"); var coll = db.getCollection("covered_sort_3"); coll.drop(); -for (i = 0; i < 100; i++) { +for (let i = 0; i < 100; i++) { coll.insert({a: i, b: "strvar_" + (i % 13), c: NumberInt(i % 10)}); } diff --git a/jstests/core/index/fts/fts2.js b/jstests/core/index/fts/fts2.js index 79be057fed8..418a8ca3215 100644 --- a/jstests/core/index/fts/fts2.js +++ b/jstests/core/index/fts/fts2.js @@ -1,6 +1,6 @@ load("jstests/libs/fts.js"); -t = db.text2; +let t = db.text2; t.drop(); t.save({_id: 1, x: "az b x", y: "c d m", z: 1}); diff --git a/jstests/core/index/fts/fts3.js b/jstests/core/index/fts/fts3.js index 9b89cda029c..b28227e57bb 100644 --- a/jstests/core/index/fts/fts3.js +++ b/jstests/core/index/fts/fts3.js @@ -1,6 +1,6 @@ load("jstests/libs/fts.js"); -t = db.text3; +let t = db.text3; t.drop(); t.save({_id: 1, x: "az b x", y: "c d m", z: 1}); diff --git a/jstests/core/index/fts/fts4.js b/jstests/core/index/fts/fts4.js index bb19fba2221..3e92b6f0574 100644 --- a/jstests/core/index/fts/fts4.js +++ b/jstests/core/index/fts/fts4.js @@ -1,6 +1,6 @@ load("jstests/libs/fts.js"); -t = db.text4; +let t = db.text4; t.drop(); t.save({_id: 1, x: ["az", "b", "x"], y: ["c", "d", "m"], z: 1}); diff --git a/jstests/core/index/fts/fts5.js b/jstests/core/index/fts/fts5.js index 28d9b48d957..13bde38545b 100644 --- a/jstests/core/index/fts/fts5.js +++ b/jstests/core/index/fts/fts5.js @@ -1,6 +1,6 @@ load("jstests/libs/fts.js"); -t = db.text5; +let t = db.text5; t.drop(); t.save({_id: 1, x: [{a: "az"}, {a: "b"}, {a: "x"}], y: ["c", "d", "m"], z: 1}); diff --git a/jstests/core/index/fts/fts_blog.js b/jstests/core/index/fts/fts_blog.js index 5208c166258..5b7b7559512 100644 --- a/jstests/core/index/fts/fts_blog.js +++ b/jstests/core/index/fts/fts_blog.js @@ -1,4 +1,4 @@ -t = db.text_blog; +let t = db.text_blog; t.drop(); t.save({_id: 1, title: "my blog post", text: "this is a new blog i am writing. yay"}); @@ -9,7 +9,7 @@ t.save({_id: 3, title: "knives are Fun", text: "this is a new blog i am writing. // specify weights if you want a field to be more meaningull t.createIndex({"title": "text", text: "text"}, {weights: {title: 10}}); -res = t.find({"$text": {"$search": "blog"}}, {score: {"$meta": "textScore"}}).sort({ +let res = t.find({"$text": {"$search": "blog"}}, {score: {"$meta": "textScore"}}).sort({ score: {"$meta": "textScore"} }); assert.eq(3, res.length()); diff --git a/jstests/core/index/fts/fts_blogwild.js b/jstests/core/index/fts/fts_blogwild.js index f449b6b827e..ffb28533e11 100644 --- a/jstests/core/index/fts/fts_blogwild.js +++ b/jstests/core/index/fts/fts_blogwild.js @@ -4,7 +4,7 @@ // assumes_no_implicit_index_creation, // ] -t = db.text_blogwild; +let t = db.text_blogwild; t.drop(); t.save({_id: 1, title: "my blog post", text: "this is a new blog i am writing. yay eliot"}); @@ -21,7 +21,7 @@ t.createIndex({dummy: "text"}, {weights: "$**"}); // ensure listIndexes can handle a string-valued "weights" assert.eq(2, t.getIndexes().length); -res = t.find({"$text": {"$search": "blog"}}); +let res = t.find({"$text": {"$search": "blog"}}); assert.eq(3, res.length(), "A1"); res = t.find({"$text": {"$search": "write"}}); diff --git a/jstests/core/index/fts/fts_partition1.js b/jstests/core/index/fts/fts_partition1.js index 4a26a3ad629..3791c461f7d 100644 --- a/jstests/core/index/fts/fts_partition1.js +++ b/jstests/core/index/fts/fts_partition1.js @@ -1,6 +1,6 @@ load("jstests/libs/fts.js"); -t = db.text_parition1; +let t = db.text_parition1; t.drop(); t.insert({_id: 1, x: 1, y: "foo"}); @@ -19,7 +19,7 @@ assert.throws(function() { assert.eq([1], queryIDS(t, "foo", {x: 1})); -res = t.find({"$text": {"$search": "foo"}, x: 1}, {score: {"$meta": "textScore"}}); +let res = t.find({"$text": {"$search": "foo"}, x: 1}, {score: {"$meta": "textScore"}}); assert(res[0].score > 0, tojson(res.toArray())); // repeat "search" with "language" specified, SERVER-8999 diff --git a/jstests/core/index/fts/fts_partition_no_multikey.js b/jstests/core/index/fts/fts_partition_no_multikey.js index b819c3abfbd..c8adead6100 100644 --- a/jstests/core/index/fts/fts_partition_no_multikey.js +++ b/jstests/core/index/fts/fts_partition_no_multikey.js @@ -1,4 +1,4 @@ -t = db.fts_partition_no_multikey; +let t = db.fts_partition_no_multikey; t.drop(); t.createIndex({x: 1, y: "text"}); diff --git a/jstests/core/index/fts/fts_phrase.js b/jstests/core/index/fts/fts_phrase.js index 1a3d7470326..31356e8a4ea 100644 --- a/jstests/core/index/fts/fts_phrase.js +++ b/jstests/core/index/fts/fts_phrase.js @@ -1,4 +1,4 @@ -t = db.text_phrase; +let t = db.text_phrase; t.drop(); t.save({_id: 1, title: "my blog post", text: "i am writing a blog. yay"}); @@ -7,7 +7,7 @@ t.save({_id: 3, title: "knives are Fun", text: "this is a new blog i am writing. t.createIndex({"title": "text", text: "text"}, {weights: {title: 10}}); -res = t.find({"$text": {"$search": "blog write"}}, {score: {"$meta": "textScore"}}).sort({ +let res = t.find({"$text": {"$search": "blog write"}}, {score: {"$meta": "textScore"}}).sort({ score: {"$meta": "textScore"} }); assert.eq(3, res.length()); diff --git a/jstests/core/index/geo/geo1.js b/jstests/core/index/geo/geo1.js index 8a80f59d692..126aae3505d 100644 --- a/jstests/core/index/geo/geo1.js +++ b/jstests/core/index/geo/geo1.js @@ -5,13 +5,10 @@ // requires_fastcount, // ] -t = db.geo1; +let t = db.geo1; t.drop(); -idx = { - loc: "2d", - zip: 1 -}; +let idx = {loc: "2d", zip: 1}; t.insert({zip: "06525", loc: [41.352964, 73.01212]}); t.insert({zip: "10024", loc: [40.786387, 73.97709]}); @@ -31,7 +28,7 @@ assert.eq(3, t.count(), "B3"); // test normal access -wb = t.findOne({zip: "06525"}); +let wb = t.findOne({zip: "06525"}); assert(wb, "C1"); assert.eq("06525", t.find({loc: wb.loc}).hint({"$natural": 1})[0].zip, "C2"); diff --git a/jstests/core/index/geo/geo10.js b/jstests/core/index/geo/geo10.js index 45463711406..adbf0862cbe 100644 --- a/jstests/core/index/geo/geo10.js +++ b/jstests/core/index/geo/geo10.js @@ -6,7 +6,7 @@ // Test for SERVER-2746 -coll = db.geo10; +let coll = db.geo10; coll.drop(); assert.commandWorked(db.geo10.createIndex({c: '2d', t: 1}, {min: 0, max: Math.pow(2, 40)})); diff --git a/jstests/core/index/geo/geo2.js b/jstests/core/index/geo/geo2.js index 34588acac9e..e4521b5b45e 100644 --- a/jstests/core/index/geo/geo2.js +++ b/jstests/core/index/geo/geo2.js @@ -3,11 +3,11 @@ // requires_fastcount, // ] -t = db.geo2; +let t = db.geo2; t.drop(); -n = 1; -arr = []; +let n = 1; +let arr = []; for (var x = -100; x < 100; x += 2) { for (var y = -100; y < 100; y += 2) { arr.push({_id: n++, loc: [x, y]}); diff --git a/jstests/core/index/geo/geo3.js b/jstests/core/index/geo/geo3.js index 7e54fd7dc5f..381ec12f399 100644 --- a/jstests/core/index/geo/geo3.js +++ b/jstests/core/index/geo/geo3.js @@ -4,11 +4,11 @@ // ] (function() { -t = db.geo3; +let t = db.geo3; t.drop(); -n = 1; -arr = []; +let n = 1; +let arr = []; for (var x = -100; x < 100; x += 2) { for (var y = -100; y < 100; y += 2) { arr.push({_id: n++, loc: [x, y], a: Math.abs(x) % 5, b: Math.abs(y) % 5}); @@ -67,9 +67,7 @@ assert.commandWorked(t.createIndex({loc: "2d", b: 1})); testFiltering("loc and b"); -q = { - loc: {$near: [50, 50]} -}; +let q = {loc: {$near: [50, 50]}}; assert.eq(100, t.find(q).limit(100).itcount(), "D1"); assert.eq(100, t.find(q).limit(100).size(), "D2"); diff --git a/jstests/core/index/geo/geo6.js b/jstests/core/index/geo/geo6.js index 8d32c066c88..98022ad7940 100644 --- a/jstests/core/index/geo/geo6.js +++ b/jstests/core/index/geo/geo6.js @@ -1,4 +1,4 @@ -t = db.geo6; +let t = db.geo6; t.drop(); t.createIndex({loc: "2d"}); diff --git a/jstests/core/index/geo/geo9.js b/jstests/core/index/geo/geo9.js index 6b1bfb60631..701c6bd6680 100644 --- a/jstests/core/index/geo/geo9.js +++ b/jstests/core/index/geo/geo9.js @@ -1,4 +1,4 @@ -t = db.geo9; +let t = db.geo9; t.drop(); t.save({_id: 1, a: [10, 10], b: [50, 50]}); @@ -15,7 +15,7 @@ t.createIndex({b: "2d"}); function check(field) { var q = {}; q[field] = {$near: [11, 11]}; - arr = t.find(q).limit(3).map(function(z) { + let arr = t.find(q).limit(3).map(function(z) { return Geo.distance([11, 11], z[field]); }); assert.eq(2 * Math.sqrt(2), Array.sum(arr), "test " + field); diff --git a/jstests/core/index/geo/geo_allowedcomparisons.js b/jstests/core/index/geo/geo_allowedcomparisons.js index 2f689f4be68..80ea1e25fee 100644 --- a/jstests/core/index/geo/geo_allowedcomparisons.js +++ b/jstests/core/index/geo/geo_allowedcomparisons.js @@ -1,33 +1,27 @@ // A test for what geometries can interact with what other geometries. -t = db.geo_allowedcomparisons; +let t = db.geo_allowedcomparisons; // Any GeoJSON object can intersect with any geojson object. -geojsonPoint = { - "type": "Point", - "coordinates": [0, 0] -}; -oldPoint = [0, 0]; +let geojsonPoint = {"type": "Point", "coordinates": [0, 0]}; +let oldPoint = [0, 0]; // GeoJSON polygons can contain any geojson object and OLD points. -geojsonPoly = { +let geojsonPoly = { "type": "Polygon", "coordinates": [[[-5, -5], [-5, 5], [5, 5], [5, -5], [-5, -5]]] }; // This can be contained by GJ polygons, intersected by anything GJ and old points. -geojsonLine = { - "type": "LineString", - "coordinates": [[0, 0], [1, 1]] -}; +let geojsonLine = {"type": "LineString", "coordinates": [[0, 0], [1, 1]]}; // $centerSphere can contain old or new points. -oldCenterSphere = [[0, 0], Math.PI / 180]; +let oldCenterSphere = [[0, 0], Math.PI / 180]; // $box can contain old points. -oldBox = [[-5, -5], [5, 5]]; +let oldBox = [[-5, -5], [5, 5]]; // $polygon can contain old points. -oldPolygon = [[-5, -5], [-5, 5], [5, 5], [5, -5], [-5, -5]]; +let oldPolygon = [[-5, -5], [-5, 5], [5, 5], [5, -5], [-5, -5]]; // $center can contain old points. -oldCenter = [[0, 0], 1]; +let oldCenter = [[0, 0], 1]; t.drop(); t.createIndex({geo: "2d"}); @@ -47,10 +41,7 @@ assert.writeError(t.insert({geo: oldCenter})); // Verify that even if we can't index them, we can use them in a matcher. t.insert({gj: geojsonLine}); t.insert({gj: geojsonPoly}); -geojsonPoint2 = { - "type": "Point", - "coordinates": [0, 0.001] -}; +let geojsonPoint2 = {"type": "Point", "coordinates": [0, 0.001]}; t.insert({gjp: geojsonPoint2}); // We convert between old and new style points. diff --git a/jstests/core/index/geo/geo_array0.js b/jstests/core/index/geo/geo_array0.js index 0c9dc096afb..29798952d60 100644 --- a/jstests/core/index/geo/geo_array0.js +++ b/jstests/core/index/geo/geo_array0.js @@ -5,7 +5,7 @@ // ] // Make sure the very basics of geo arrays are sane by creating a few multi location docs -t = db.geoarray; +let t = db.geoarray; function test(index) { t.drop(); diff --git a/jstests/core/index/geo/geo_array2.js b/jstests/core/index/geo/geo_array2.js index 7da56a576eb..7e09608c07e 100644 --- a/jstests/core/index/geo/geo_array2.js +++ b/jstests/core/index/geo/geo_array2.js @@ -1,6 +1,6 @@ // Check the semantics of near calls with multiple locations -t = db.geoarray2; +let t = db.geoarray2; t.drop(); var numObjs = 10; @@ -12,7 +12,7 @@ Random.setRandomSeed(); for (var i = -1; i < 2; i++) { for (var j = -1; j < 2; j++) { - locObj = []; + let locObj = []; if (i != 0 || j != 0) locObj.push({x: i * 50 + Random.rand(), y: j * 50 + Random.rand()}); @@ -28,7 +28,7 @@ assert.commandWorked(t.createIndex({loc: "2d", type: 1})); print("Starting testing phase... "); -for (var t = 0; t < 2; t++) { +for (let t = 0; t < 2; t++) { var type = t == 0 ? "A" : "B"; for (var i = -1; i < 2; i++) { diff --git a/jstests/core/index/geo/geo_big_polygon2.js b/jstests/core/index/geo/geo_big_polygon2.js index 389bc9ef7bc..a4dc09a132e 100644 --- a/jstests/core/index/geo/geo_big_polygon2.js +++ b/jstests/core/index/geo/geo_big_polygon2.js @@ -461,9 +461,9 @@ function nGonGenerator(N, D, clockwise, LON, LAT) { lat = (-D / 2); } lon = Math.sqrt((D / 2) * (D / 2) - (lat * lat)); - newlat = lat + LAT; - newlon = lon + LON; - conjugateLon = LON - lon; + let newlat = lat + LAT; + let newlon = lon + LON; + let conjugateLon = LON - lon; pts[i] = [newlon, newlat]; pts[N - i] = [conjugateLon, newlat]; } diff --git a/jstests/core/index/geo/geo_borders.js b/jstests/core/index/geo/geo_borders.js index 897697a88cb..09b89c0d753 100644 --- a/jstests/core/index/geo/geo_borders.js +++ b/jstests/core/index/geo/geo_borders.js @@ -4,16 +4,16 @@ * ] */ -t = db.borders; +let t = db.borders; t.drop(); -epsilon = 0.0001; +let epsilon = 0.0001; // For these tests, *required* that step ends exactly on max -min = -1; -max = 1; -step = 1; -numItems = 0; +let min = -1; +let max = 1; +let step = 1; +let numItems = 0; for (var x = min; x <= max; x += step) { for (var y = min; y <= max; y += step) { @@ -22,8 +22,8 @@ for (var x = min; x <= max; x += step) { } } -overallMin = -1; -overallMax = 1; +let overallMin = -1; +let overallMax = 1; // Create a point index slightly smaller than the points we have var res = @@ -113,14 +113,14 @@ assert.eq(numItems, t.find({ // Circle tests // ************** -center = (overallMax + overallMin) / 2; +let center = (overallMax + overallMin) / 2; center = [center, center]; -radius = overallMax; +let radius = overallMax; -offCenter = [center[0] + radius, center[1] + radius]; -onBounds = [offCenter[0] + epsilon, offCenter[1] + epsilon]; -offBounds = [onBounds[0] + epsilon, onBounds[1] + epsilon]; -onBoundsNeg = [-onBounds[0], -onBounds[1]]; +let offCenter = [center[0] + radius, center[1] + radius]; +let onBounds = [offCenter[0] + epsilon, offCenter[1] + epsilon]; +let offBounds = [onBounds[0] + epsilon, onBounds[1] + epsilon]; +let onBoundsNeg = [-onBounds[0], -onBounds[1]]; // Make sure we can get all points when radius is exactly at full bounds assert.lt(0, t.find({loc: {$within: {$center: [center, radius + epsilon]}}}).count()); @@ -133,7 +133,7 @@ assert.lt(0, t.find({loc: {$within: {$center: [offCenter, radius + 2 * epsilon]} // Make sure we get correct corner point when center is in bounds // (x bounds wrap, so could get other corner) -cornerPt = t.findOne({loc: {$within: {$center: [offCenter, step / 2]}}}); +let cornerPt = t.findOne({loc: {$within: {$center: [offCenter, step / 2]}}}); assert.eq(cornerPt.loc.y, overallMax); // Make sure we get correct corner point when center is on bounds diff --git a/jstests/core/index/geo/geo_box1.js b/jstests/core/index/geo/geo_box1.js index d0c4ff50bdf..40a754d64b3 100644 --- a/jstests/core/index/geo/geo_box1.js +++ b/jstests/core/index/geo/geo_box1.js @@ -2,32 +2,32 @@ // requires_getmore, // ] -t = db.geo_box1; +let t = db.geo_box1; t.drop(); -num = 0; -for (x = 0; x <= 20; x++) { - for (y = 0; y <= 20; y++) { - o = {_id: num++, loc: [x, y]}; +let num = 0; +for (let x = 0; x <= 20; x++) { + for (let y = 0; y <= 20; y++) { + let o = {_id: num++, loc: [x, y]}; t.save(o); } } t.createIndex({loc: "2d"}); -searches = [ +let searches = [ [[1, 2], [4, 5]], [[1, 1], [2, 2]], [[0, 2], [4, 5]], [[1, 1], [2, 8]], ]; -for (i = 0; i < searches.length; i++) { - b = searches[i]; +for (let i = 0; i < searches.length; i++) { + let b = searches[i]; // printjson( b ); - q = {loc: {$within: {$box: b}}}; - numWanetd = (1 + b[1][0] - b[0][0]) * (1 + b[1][1] - b[0][1]); + let q = {loc: {$within: {$box: b}}}; + let numWanetd = (1 + b[1][0] - b[0][0]) * (1 + b[1][1] - b[0][1]); assert.eq(numWanetd, t.find(q).itcount(), "itcount: " + tojson(q)); printjson(t.find(q).explain()); } diff --git a/jstests/core/index/geo/geo_box1_noindex.js b/jstests/core/index/geo/geo_box1_noindex.js index 879f17e3002..3da72a96b44 100644 --- a/jstests/core/index/geo/geo_box1_noindex.js +++ b/jstests/core/index/geo/geo_box1_noindex.js @@ -3,28 +3,28 @@ // ] // SERVER-7343: allow $within without a geo index. -t = db.geo_box1_noindex; +let t = db.geo_box1_noindex; t.drop(); -num = 0; -for (x = 0; x <= 20; x++) { - for (y = 0; y <= 20; y++) { - o = {_id: num++, loc: [x, y]}; +let num = 0; +for (let x = 0; x <= 20; x++) { + for (let y = 0; y <= 20; y++) { + let o = {_id: num++, loc: [x, y]}; t.save(o); } } -searches = [ +let searches = [ [[1, 2], [4, 5]], [[1, 1], [2, 2]], [[0, 2], [4, 5]], [[1, 1], [2, 8]], ]; -for (i = 0; i < searches.length; i++) { - b = searches[i]; - q = {loc: {$within: {$box: b}}}; - numWanted = (1 + b[1][0] - b[0][0]) * (1 + b[1][1] - b[0][1]); +for (let i = 0; i < searches.length; i++) { + let b = searches[i]; + let q = {loc: {$within: {$box: b}}}; + let numWanted = (1 + b[1][0] - b[0][0]) * (1 + b[1][1] - b[0][1]); assert.eq(numWanted, t.find(q).itcount(), "itcount: " + tojson(q)); printjson(t.find(q).explain()); } diff --git a/jstests/core/index/geo/geo_box2.js b/jstests/core/index/geo/geo_box2.js index 7120cfd3e4a..60c76603b5b 100644 --- a/jstests/core/index/geo/geo_box2.js +++ b/jstests/core/index/geo/geo_box2.js @@ -1,9 +1,9 @@ -t = db.geo_box2; +let t = db.geo_box2; t.drop(); -for (i = 1; i < 10; i++) { - for (j = 1; j < 10; j++) { +for (let i = 1; i < 10; i++) { + for (let j = 1; j < 10; j++) { t.insert({loc: [i, j]}); } } diff --git a/jstests/core/index/geo/geo_box3.js b/jstests/core/index/geo/geo_box3.js index 4a91ffb0d1d..3ca3d4b82e3 100644 --- a/jstests/core/index/geo/geo_box3.js +++ b/jstests/core/index/geo/geo_box3.js @@ -4,7 +4,7 @@ // bounding box. // This is the bug reported in SERVER-994. -t = db.geo_box3; +let t = db.geo_box3; t.drop(); t.insert({point: {x: -15000000, y: 10000000}}); t.createIndex({point: "2d"}, {min: -21000000, max: 21000000}); diff --git a/jstests/core/index/geo/geo_center_sphere1.js b/jstests/core/index/geo/geo_center_sphere1.js index 2b37c7c3f96..c3cdb5aa7d0 100644 --- a/jstests/core/index/geo/geo_center_sphere1.js +++ b/jstests/core/index/geo/geo_center_sphere1.js @@ -3,13 +3,14 @@ // requires_fastcount, // ] -t = db.geo_center_sphere1; +let t = db.geo_center_sphere1; function test(index) { t.drop(); - skip = 8; // lower for more rigor, higher for more speed (tested with .5, .678, 1, 2, 3, and 4) + let skip = + 8; // lower for more rigor, higher for more speed (tested with .5, .678, 1, 2, 3, and 4) - searches = [ + let searches = [ // x , y rad [[5, 0], 0.05], // ~200 miles [[135, 0], 0.05], @@ -23,18 +24,18 @@ function test(index) { [[-20, 60], 0.25], [[-20, -70], 0.25], ]; - correct = searches.map(function(z) { + let correct = searches.map(function(z) { return []; }); - num = 0; + let num = 0; var bulk = t.initializeUnorderedBulkOp(); - for (x = -179; x <= 179; x += skip) { - for (y = -89; y <= 89; y += skip) { - o = {_id: num++, loc: [x, y]}; + for (let x = -179; x <= 179; x += skip) { + for (let y = -89; y <= 89; y += skip) { + let o = {_id: num++, loc: [x, y]}; bulk.insert(o); - for (i = 0; i < searches.length; i++) { + for (let i = 0; i < searches.length; i++) { if (Geo.sphereDistance([x, y], searches[i][0]) <= searches[i][1]) correct[i].push(o); } @@ -47,10 +48,10 @@ function test(index) { t.createIndex({loc: index}); } - for (i = 0; i < searches.length; i++) { + for (let i = 0; i < searches.length; i++) { print('------------'); print(tojson(searches[i]) + "\t" + correct[i].length); - q = {loc: {$within: {$centerSphere: searches[i]}}}; + let q = {loc: {$within: {$centerSphere: searches[i]}}}; // correct[i].forEach( printjson ) // printjson( q ); @@ -69,8 +70,8 @@ function test(index) { return z._id; }); - missing = []; - epsilon = 0.001; // allow tenth of a percent error due to conversions + let missing = []; + let epsilon = 0.001; // allow tenth of a percent error due to conversions for (var j = 0; j < x.length; j++) { if (!Array.contains(y, x[j])) { missing.push(x[j]); diff --git a/jstests/core/index/geo/geo_center_sphere2.js b/jstests/core/index/geo/geo_center_sphere2.js index 1c59850d841..ecf3622217c 100644 --- a/jstests/core/index/geo/geo_center_sphere2.js +++ b/jstests/core/index/geo/geo_center_sphere2.js @@ -18,8 +18,8 @@ function computexscandist(y, maxDistDegrees) { } function pointIsOK(startPoint, radius) { - yscandist = rad2deg(radius) + 0.01; - xscandist = computexscandist(startPoint[1], yscandist); + let yscandist = rad2deg(radius) + 0.01; + let xscandist = computexscandist(startPoint[1], yscandist); return (startPoint[0] + xscandist < 180) && (startPoint[0] - xscandist > -180) && (startPoint[1] + yscandist < 90) && (startPoint[1] - yscandist > -90); } diff --git a/jstests/core/index/geo/geo_circle2.js b/jstests/core/index/geo/geo_circle2.js index d7947f96502..1d228db988c 100644 --- a/jstests/core/index/geo/geo_circle2.js +++ b/jstests/core/index/geo/geo_circle2.js @@ -1,4 +1,4 @@ -t = db.geo_circle2; +let t = db.geo_circle2; t.drop(); t.createIndex({loc: "2d", categories: 1}, {"name": "placesIdx", "min": -100, "max": 100}); diff --git a/jstests/core/index/geo/geo_circle3.js b/jstests/core/index/geo/geo_circle3.js index da7a9af6b34..9466f1e0c5f 100644 --- a/jstests/core/index/geo/geo_circle3.js +++ b/jstests/core/index/geo/geo_circle3.js @@ -1,7 +1,7 @@ // SERVER-848 and SERVER-1191. db.places.drop(); -n = 0; +let n = 0; db.places.save({"_id": n++, "loc": {"x": 4.9999, "y": 52}}); db.places.save({"_id": n++, "loc": {"x": 5, "y": 52}}); db.places.save({"_id": n++, "loc": {"x": 5.0001, "y": 52}}); @@ -12,8 +12,8 @@ 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.createIndex({loc: "2d"}); -radius = 0.0001; -center = [5, 52]; +let radius = 0.0001; +let center = [5, 52]; // print(db.places.find({"loc" : {"$within" : {"$center" : [center, radius]}}}).count()) // FIXME: we want an assert, e.g., that there be 5 answers in the find(). db.places.find({"loc": {"$within": {"$center": [center, radius]}}}).forEach(printjson); diff --git a/jstests/core/index/geo/geo_circle4.js b/jstests/core/index/geo/geo_circle4.js index c2194142795..50cff15512f 100644 --- a/jstests/core/index/geo/geo_circle4.js +++ b/jstests/core/index/geo/geo_circle4.js @@ -2,8 +2,8 @@ function test(index) { db.server848.drop(); - radius = 0.0001; - center = [5, 52]; + let radius = 0.0001; + let center = [5, 52]; db.server848.save({"_id": 1, "loc": {"x": 4.9999, "y": 52}}); db.server848.save({"_id": 2, "loc": {"x": 5, "y": 52}}); @@ -17,12 +17,12 @@ function test(index) { if (index) { db.server848.createIndex({loc: "2d"}); } - r = db.server848.find({"loc": {"$within": {"$center": [center, radius]}}}, {_id: 1}); + let r = db.server848.find({"loc": {"$within": {"$center": [center, radius]}}}, {_id: 1}); assert.eq(5, r.count(), "A1"); // FIXME: surely code like this belongs in utils.js. - a = r.toArray(); - x = []; - for (k in a) { + let a = r.toArray(); + let x = []; + for (let k in a) { x.push(a[k]["_id"]); } x.sort(); diff --git a/jstests/core/index/geo/geo_circle5.js b/jstests/core/index/geo/geo_circle5.js index 27b973a8ede..4f43d8b3bec 100644 --- a/jstests/core/index/geo/geo_circle5.js +++ b/jstests/core/index/geo/geo_circle5.js @@ -12,9 +12,9 @@ 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}); -c1 = db.server1238.find({"loc": {"$within": {"$center": [[5000000, 900000], 1.0]}}}).count(); +let c1 = db.server1238.find({"loc": {"$within": {"$center": [[5000000, 900000], 1.0]}}}).count(); -c2 = db.server1238.find({"loc": {"$within": {"$center": [[5000001, 900000], 5.0]}}}).count(); +let c2 = db.server1238.find({"loc": {"$within": {"$center": [[5000001, 900000], 5.0]}}}).count(); assert.eq(4, c1, "A1"); assert.eq(c1, c2, "B1"); diff --git a/jstests/core/index/geo/geo_exactfetch.js b/jstests/core/index/geo/geo_exactfetch.js index 43ef46fb558..6ced564107f 100644 --- a/jstests/core/index/geo/geo_exactfetch.js +++ b/jstests/core/index/geo/geo_exactfetch.js @@ -1,5 +1,5 @@ // SERVER-7322 -t = db.geo_exactfetch; +let t = db.geo_exactfetch; t.drop(); function test(indexname) { diff --git a/jstests/core/index/geo/geo_fiddly_box.js b/jstests/core/index/geo/geo_fiddly_box.js index 9f5a9e8d6c4..84e58aa60e3 100644 --- a/jstests/core/index/geo/geo_fiddly_box.js +++ b/jstests/core/index/geo/geo_fiddly_box.js @@ -8,7 +8,7 @@ // "expand" portion of the geo-lookup expands the 2d range in only one // direction (so points are required on either side of the expanding range) -t = db.geo_fiddly_box; +let t = db.geo_fiddly_box; t.drop(); t.createIndex({loc: "2d"}); @@ -28,11 +28,11 @@ assert.eq( // Test normal lookup of a small square of points as a sanity check. -epsilon = 0.0001; -min = -1; -max = 1; -step = 1; -numItems = 0; +let epsilon = 0.0001; +let min = -1; +let max = 1; +let step = 1; +let numItems = 0; t.drop(); t.createIndex({loc: "2d"}, {max: max + epsilon / 2, min: min - epsilon / 2}); diff --git a/jstests/core/index/geo/geo_fiddly_box2.js b/jstests/core/index/geo/geo_fiddly_box2.js index a0f87203163..c71c4778603 100644 --- a/jstests/core/index/geo/geo_fiddly_box2.js +++ b/jstests/core/index/geo/geo_fiddly_box2.js @@ -4,7 +4,7 @@ // required to do // exact lookups on the points to get correct results. -t = db.geo_fiddly_box2; +let t = db.geo_fiddly_box2; t.drop(); t.insert({"letter": "S", "position": [-3, 0]}); @@ -17,7 +17,7 @@ t.insert({"letter": "L", "position": [3, 0]}); t.insert({"letter": "E", "position": [4, 0]}); t.createIndex({position: "2d"}); -result = t.find({"position": {"$within": {"$box": [[-3, -1], [0, 1]]}}}); +let result = t.find({"position": {"$within": {"$box": [[-3, -1], [0, 1]]}}}); assert.eq(4, result.count()); t.dropIndex({position: "2d"}); diff --git a/jstests/core/index/geo/geo_invalid_polygon.js b/jstests/core/index/geo/geo_invalid_polygon.js index 0eab7ca5406..7736f260731 100644 --- a/jstests/core/index/geo/geo_invalid_polygon.js +++ b/jstests/core/index/geo/geo_invalid_polygon.js @@ -1,6 +1,6 @@ // With invalid geometry, error message should include _id // SERVER-8992 -t = db.geo_invalid_polygon; +let t = db.geo_invalid_polygon; t.drop(); // Self-intersecting polygon, triggers diff --git a/jstests/core/index/geo/geo_max.js b/jstests/core/index/geo/geo_max.js index 3ef6e39dcaa..8db0cbb5858 100644 --- a/jstests/core/index/geo/geo_max.js +++ b/jstests/core/index/geo/geo_max.js @@ -16,10 +16,10 @@ test.t.insert({loc: [-180, 0]}); test.t.insert({loc: [179.999, 0]}); test.t.insert({loc: [-179.999, 0]}); -assertXIsNegative = function(obj) { +let assertXIsNegative = function(obj) { assert.lt(obj.loc[0], 0); }; -assertXIsPositive = function(obj) { +let assertXIsPositive = function(obj) { assert.gt(obj.loc[0], 0); }; diff --git a/jstests/core/index/geo/geo_multikey0.js b/jstests/core/index/geo/geo_multikey0.js index 27075a779ee..8296dcd6854 100644 --- a/jstests/core/index/geo/geo_multikey0.js +++ b/jstests/core/index/geo/geo_multikey0.js @@ -1,6 +1,6 @@ // Multikey geo values tests - SERVER-3793. -t = db.jstests_geo_multikey0; +let t = db.jstests_geo_multikey0; t.drop(); // Check that conflicting constraints are satisfied by parallel array elements. diff --git a/jstests/core/index/geo/geo_multikey1.js b/jstests/core/index/geo/geo_multikey1.js index e6d0ec086da..3bdbea42272 100644 --- a/jstests/core/index/geo/geo_multikey1.js +++ b/jstests/core/index/geo/geo_multikey1.js @@ -1,11 +1,11 @@ // Multikey geo index tests with parallel arrays. -t = db.jstests_geo_multikey1; +let t = db.jstests_geo_multikey1; t.drop(); -locArr = []; -arr = []; -for (i = 0; i < 10; ++i) { +let locArr = []; +let arr = []; +for (let i = 0; i < 10; ++i) { locArr.push([i, i + 1]); arr.push(i); } diff --git a/jstests/core/index/geo/geo_multinest0.js b/jstests/core/index/geo/geo_multinest0.js index 746a530e19b..11111f17a55 100644 --- a/jstests/core/index/geo/geo_multinest0.js +++ b/jstests/core/index/geo/geo_multinest0.js @@ -6,7 +6,7 @@ // Make sure nesting of location arrays also works. -t = db.geonest; +let t = db.geonest; t.drop(); t.insert({zip: "10001", data: [{loc: [10, 10], type: "home"}, {loc: [50, 50], type: "work"}]}); diff --git a/jstests/core/index/geo/geo_multinest1.js b/jstests/core/index/geo/geo_multinest1.js index b6aa53cae16..4cc829e79ba 100644 --- a/jstests/core/index/geo/geo_multinest1.js +++ b/jstests/core/index/geo/geo_multinest1.js @@ -6,7 +6,7 @@ // Test distance queries with interleaved distances -t = db.multinest; +let t = db.multinest; t.drop(); t.insert({zip: "10001", data: [{loc: [10, 10], type: "home"}, {loc: [29, 29], type: "work"}]}); diff --git a/jstests/core/index/geo/geo_near_random1.js b/jstests/core/index/geo/geo_near_random1.js index 1573e72c1f8..b1f5457bdef 100644 --- a/jstests/core/index/geo/geo_near_random1.js +++ b/jstests/core/index/geo/geo_near_random1.js @@ -18,9 +18,7 @@ test.testPt(test.mkPt()); test.testPt(test.mkPt()); test.testPt(test.mkPt()); -opts = { - sphere: 1 -}; +let opts = {sphere: 1}; // Test $nearSphere with a 2d index test.testPt([0, 0], opts); diff --git a/jstests/core/index/geo/geo_near_random2.js b/jstests/core/index/geo/geo_near_random2.js index a9e242edbcc..257b27f4f31 100644 --- a/jstests/core/index/geo/geo_near_random2.js +++ b/jstests/core/index/geo/geo_near_random2.js @@ -18,10 +18,7 @@ test.insertPts(5000); // distances are in increasing order. The test runs in O(N^2). // Test $near with 2d index -opts = { - sphere: 0, - nToTest: test.nPts * 0.01 -}; +let opts = {sphere: 0, nToTest: test.nPts * 0.01}; test.testPt([0, 0], opts); test.testPt(test.mkPt(), opts); test.testPt(test.mkPt(), opts); diff --git a/jstests/core/index/geo/geo_or.js b/jstests/core/index/geo/geo_or.js index cee91d4929d..a8fe7ae7b5e 100644 --- a/jstests/core/index/geo/geo_or.js +++ b/jstests/core/index/geo/geo_or.js @@ -1,6 +1,6 @@ // multiple geo clauses with $or -t = db.geoor; +let t = db.geoor; t.drop(); diff --git a/jstests/core/index/geo/geo_poly_line.js b/jstests/core/index/geo/geo_poly_line.js index 85dc9274158..58a1ae215f8 100644 --- a/jstests/core/index/geo/geo_poly_line.js +++ b/jstests/core/index/geo/geo_poly_line.js @@ -1,6 +1,6 @@ // Test that weird polygons work SERVER-3725 -t = db.geo_polygon5; +let t = db.geo_polygon5; t.drop(); t.insert({loc: [0, 0]}); diff --git a/jstests/core/index/geo/geo_polygon1_noindex.js b/jstests/core/index/geo/geo_polygon1_noindex.js index 5f43f736b45..8b441c81dc4 100644 --- a/jstests/core/index/geo/geo_polygon1_noindex.js +++ b/jstests/core/index/geo/geo_polygon1_noindex.js @@ -1,22 +1,22 @@ // SERVER-7343: allow $within without a geo index. -t = db.geo_polygon1_noindex; +let t = db.geo_polygon1_noindex; t.drop(); -num = 0; -for (x = 1; x < 9; x++) { - for (y = 1; y < 9; y++) { - o = {_id: num++, loc: [x, y]}; +let num = 0; +for (let x = 1; x < 9; x++) { + for (let y = 1; y < 9; y++) { + let o = {_id: num++, loc: [x, y]}; t.save(o); } } -triangle = [[0, 0], [1, 1], [0, 2]]; +let triangle = [[0, 0], [1, 1], [0, 2]]; // Look at only a small slice of the data within a triangle assert.eq(1, t.find({loc: {"$within": {"$polygon": triangle}}}).count(), "Triangle Test"); -boxBounds = [[0, 0], [0, 10], [10, 10], [10, 0]]; +let boxBounds = [[0, 0], [0, 10], [10, 10], [10, 0]]; assert.eq(num, t.find({loc: {"$within": {"$polygon": boxBounds}}}).count(), "Bounding Box Test"); @@ -33,7 +33,7 @@ assert.eq( t.drop(); -pacman = [ +let pacman = [ [0, 2], [0, 4], [2, 6], diff --git a/jstests/core/index/geo/geo_polygon2.js b/jstests/core/index/geo/geo_polygon2.js index 7a6ad0aedb5..0452b28f563 100644 --- a/jstests/core/index/geo/geo_polygon2.js +++ b/jstests/core/index/geo/geo_polygon2.js @@ -29,8 +29,8 @@ for (var test = 0; test < numTests; test++) { x = x[0]; } - xp = x * Math.cos(rotation) - y * Math.sin(rotation); - yp = y * Math.cos(rotation) + x * Math.sin(rotation); + let xp = x * Math.cos(rotation) - y * Math.sin(rotation); + let yp = y * Math.cos(rotation) + x * Math.sin(rotation); var scaleX = (bounds[1] - bounds[0]) / 360; var scaleY = (bounds[1] - bounds[0]) / 360; @@ -121,12 +121,13 @@ for (var test = 0; test < numTests; test++) { } } - turtlePaths = []; + let turtlePaths = []; for (var t = 0; t < numTurtles; t++) { - turtlePath = []; + let turtlePath = []; var nextSeg = function(currTurtle, prevTurtle) { var pathX = currTurtle[0]; + let pathY; if (currTurtle[1] < prevTurtle[1]) { pathX = currTurtle[0] + 1; @@ -150,15 +151,15 @@ for (var test = 0; test < numTests; test++) { }; for (var s = 1; s < turtles[t].length; s++) { - currTurtle = turtles[t][s]; - prevTurtle = turtles[t][s - 1]; + let currTurtle = turtles[t][s]; + let prevTurtle = turtles[t][s - 1]; turtlePath.push(nextSeg(currTurtle, prevTurtle)); } for (var s = turtles[t].length - 2; s >= 0; s--) { - currTurtle = turtles[t][s]; - prevTurtle = turtles[t][s + 1]; + let currTurtle = turtles[t][s]; + let prevTurtle = turtles[t][s + 1]; turtlePath.push(nextSeg(currTurtle, prevTurtle)); } @@ -169,7 +170,7 @@ for (var test = 0; test < numTests; test++) { var lastTurtle = turtles[t][turtles[t].length - 1]; grid[lastTurtle[0]][lastTurtle[1]] = undefined; - fixedTurtlePath = []; + let fixedTurtlePath = []; for (var s = 1; s < turtlePath.length; s++) { if (turtlePath[s - 1][0] == turtlePath[s][0] && turtlePath[s - 1][1] == turtlePath[s][1]) { @@ -236,7 +237,7 @@ for (var test = 0; test < numTests; test++) { t.insert({loc: allPointsIn}); t.insert({loc: allPointsOut}); - allPoints = allPointsIn.concat(allPointsOut); + let allPoints = allPointsIn.concat(allPointsOut); t.insert({loc: allPoints}); print("Points : "); diff --git a/jstests/core/index/geo/geo_queryoptimizer.js b/jstests/core/index/geo/geo_queryoptimizer.js index 199cedf5330..a9c3378925f 100644 --- a/jstests/core/index/geo/geo_queryoptimizer.js +++ b/jstests/core/index/geo/geo_queryoptimizer.js @@ -1,4 +1,4 @@ -t = db.geo_qo1; +let t = db.geo_qo1; t.drop(); t.createIndex({loc: "2d"}); diff --git a/jstests/core/index/geo/geo_regex0.js b/jstests/core/index/geo/geo_regex0.js index 7629c193ea2..1a7ef2ffde6 100644 --- a/jstests/core/index/geo/geo_regex0.js +++ b/jstests/core/index/geo/geo_regex0.js @@ -1,22 +1,15 @@ // From SERVER-2247 // Tests to make sure regex works with geo indices -t = db.regex0; +let t = db.regex0; t.drop(); t.createIndex({point: '2d', words: 1}); t.insert({point: [1, 1], words: ['foo', 'bar']}); -regex = { - words: /^f/ -}; -geo = { - point: {$near: [1, 1]} -}; -both = { - point: {$near: [1, 1]}, - words: /^f/ -}; +let regex = {words: /^f/}; +let geo = {point: {$near: [1, 1]}}; +let both = {point: {$near: [1, 1]}, words: /^f/}; assert.eq(1, t.find(regex).count()); assert.eq(1, t.find(geo).count()); diff --git a/jstests/core/index/geo/geo_s2dedupnear.js b/jstests/core/index/geo/geo_s2dedupnear.js index ad1674f1e6e..89a1c705c71 100644 --- a/jstests/core/index/geo/geo_s2dedupnear.js +++ b/jstests/core/index/geo/geo_s2dedupnear.js @@ -1,6 +1,6 @@ // Make sure that we don't return several of the same result due to faulty // assumptions about the btree cursor. That is, don't return duplicate results. -t = db.geo_s2dedupnear; +let t = db.geo_s2dedupnear; t.drop(); t.createIndex({geo: "2dsphere"}); @@ -9,5 +9,5 @@ var x = { "coordinates": [[[100.0, 0.0], [101.0, 0.0], [101.0, 1.0], [100.0, 1.0], [100.0, 0.0]]] }; t.insert({geo: x}); -res = t.find({geo: {$geoNear: {"type": "Point", "coordinates": [31, 41]}}}); +let res = t.find({geo: {$geoNear: {"type": "Point", "coordinates": [31, 41]}}}); assert.eq(res.itcount(), 1); diff --git a/jstests/core/index/geo/geo_s2dupe_points.js b/jstests/core/index/geo/geo_s2dupe_points.js index 9f94f69caaa..54f9b3b3fc8 100644 --- a/jstests/core/index/geo/geo_s2dupe_points.js +++ b/jstests/core/index/geo/geo_s2dupe_points.js @@ -2,7 +2,7 @@ // s2 rejects shapes with duplicate adjacent points as invalid, but they are // valid in GeoJSON. We store the duplicates, but internally remove them // before indexing or querying. -t = db.geo_s2dupe_points; +let t = db.geo_s2dupe_points; t.drop(); t.createIndex({geo: "2dsphere"}); diff --git a/jstests/core/index/geo/geo_s2edgecases.js b/jstests/core/index/geo/geo_s2edgecases.js index 6e4633f58c8..b083ea88ae0 100644 --- a/jstests/core/index/geo/geo_s2edgecases.js +++ b/jstests/core/index/geo/geo_s2edgecases.js @@ -1,51 +1,42 @@ -t = db.geo_s2edgecases; +let t = db.geo_s2edgecases; t.drop(); -roundworldpoint = { - "type": "Point", - "coordinates": [180, 0] -}; +let roundworldpoint = {"type": "Point", "coordinates": [180, 0]}; // Opposite the equator -roundworld = { +let roundworld = { "type": "Polygon", "coordinates": [[[179, 1], [-179, 1], [-179, -1], [179, -1], [179, 1]]] }; t.insert({geo: roundworld}); -roundworld2 = { +let roundworld2 = { "type": "Polygon", "coordinates": [[[179, 1], [179, -1], [-179, -1], [-179, 1], [179, 1]]] }; t.insert({geo: roundworld2}); // North pole -santapoint = { - "type": "Point", - "coordinates": [180, 90] -}; -santa = { +let santapoint = {"type": "Point", "coordinates": [180, 90]}; +let santa = { "type": "Polygon", "coordinates": [[[179, 89], [179, 90], [-179, 90], [-179, 89], [179, 89]]] }; t.insert({geo: santa}); -santa2 = { +let santa2 = { "type": "Polygon", "coordinates": [[[179, 89], [-179, 89], [-179, 90], [179, 90], [179, 89]]] }; t.insert({geo: santa2}); // South pole -penguinpoint = { - "type": "Point", - "coordinates": [0, -90] -}; -penguin1 = { +let penguinpoint = {"type": "Point", "coordinates": [0, -90]}; +let penguin1 = { "type": "Polygon", "coordinates": [[[0, -89], [0, -90], [179, -90], [179, -89], [0, -89]]] }; t.insert({geo: penguin1}); -penguin2 = { +let penguin2 = { "type": "Polygon", "coordinates": [[[0, -89], [179, -89], [179, -90], [0, -90], [0, -89]]] }; @@ -53,7 +44,7 @@ t.insert({geo: penguin2}); t.createIndex({geo: "2dsphere", nonGeo: 1}); -res = t.find({"geo": {"$geoIntersects": {"$geometry": roundworldpoint}}}); +let res = t.find({"geo": {"$geoIntersects": {"$geometry": roundworldpoint}}}); assert.eq(res.count(), 2); res = t.find({"geo": {"$geoIntersects": {"$geometry": santapoint}}}); assert.eq(res.count(), 2); diff --git a/jstests/core/index/geo/geo_s2exact.js b/jstests/core/index/geo/geo_s2exact.js index 92ce551d873..eb563498c07 100644 --- a/jstests/core/index/geo/geo_s2exact.js +++ b/jstests/core/index/geo/geo_s2exact.js @@ -1,5 +1,5 @@ // Queries on exact geometry should return the exact geometry. -t = db.geo_s2exact; +let t = db.geo_s2exact; t.drop(); function test(geometry) { @@ -10,20 +10,11 @@ function test(geometry) { t.dropIndex({geo: "2dsphere"}); } -pointA = { - "type": "Point", - "coordinates": [40, 5] -}; +let pointA = {"type": "Point", "coordinates": [40, 5]}; test(pointA); -someline = { - "type": "LineString", - "coordinates": [[40, 5], [41, 6]] -}; +let someline = {"type": "LineString", "coordinates": [[40, 5], [41, 6]]}; test(someline); -somepoly = { - "type": "Polygon", - "coordinates": [[[40, 5], [40, 6], [41, 6], [41, 5], [40, 5]]] -}; +let somepoly = {"type": "Polygon", "coordinates": [[[40, 5], [40, 6], [41, 6], [41, 5], [40, 5]]]}; test(somepoly); diff --git a/jstests/core/index/geo/geo_s2index.js b/jstests/core/index/geo/geo_s2index.js index af4475a79cb..9ffdc2c02a0 100644 --- a/jstests/core/index/geo/geo_s2index.js +++ b/jstests/core/index/geo/geo_s2index.js @@ -1,56 +1,36 @@ -t = db.geo_s2index; +let t = db.geo_s2index; t.drop(); // We internally drop adjacent duplicate points in lines. -someline = { - "type": "LineString", - "coordinates": [[40, 5], [40, 5], [40, 5], [41, 6], [41, 6]] -}; +let someline = {"type": "LineString", "coordinates": [[40, 5], [40, 5], [40, 5], [41, 6], [41, 6]]}; t.insert({geo: someline, nonGeo: "someline"}); t.createIndex({geo: "2dsphere"}); -foo = t.find({geo: {$geoIntersects: {$geometry: {type: "Point", coordinates: [40, 5]}}}}).next(); +let foo = + t.find({geo: {$geoIntersects: {$geometry: {type: "Point", coordinates: [40, 5]}}}}).next(); assert.eq(foo.geo, someline); t.dropIndex({geo: "2dsphere"}); -pointA = { - "type": "Point", - "coordinates": [40, 5] -}; +let pointA = {"type": "Point", "coordinates": [40, 5]}; t.insert({geo: pointA, nonGeo: "pointA"}); -pointD = { - "type": "Point", - "coordinates": [41.001, 6.001] -}; +let pointD = {"type": "Point", "coordinates": [41.001, 6.001]}; t.insert({geo: pointD, nonGeo: "pointD"}); -pointB = { - "type": "Point", - "coordinates": [41, 6] -}; +let pointB = {"type": "Point", "coordinates": [41, 6]}; t.insert({geo: pointB, nonGeo: "pointB"}); -pointC = { - "type": "Point", - "coordinates": [41, 6] -}; +let pointC = {"type": "Point", "coordinates": [41, 6]}; t.insert({geo: pointC}); // Add a point within the polygon but not on the border. Don't want to be on // the path of the polyline. -pointE = { - "type": "Point", - "coordinates": [40.6, 5.4] -}; +let pointE = {"type": "Point", "coordinates": [40.6, 5.4]}; t.insert({geo: pointE}); // Make sure we can index this without error. t.insert({nonGeo: "noGeoField!"}); -somepoly = { - "type": "Polygon", - "coordinates": [[[40, 5], [40, 6], [41, 6], [41, 5], [40, 5]]] -}; +let somepoly = {"type": "Polygon", "coordinates": [[[40, 5], [40, 6], [41, 6], [41, 5], [40, 5]]]}; t.insert({geo: somepoly, nonGeo: "somepoly"}); var res = t.createIndex({geo: "2dsphere", nonGeo: 1}); diff --git a/jstests/core/index/geo/geo_s2indexoldformat.js b/jstests/core/index/geo/geo_s2indexoldformat.js index ffe472464d4..ad1008115dd 100644 --- a/jstests/core/index/geo/geo_s2indexoldformat.js +++ b/jstests/core/index/geo/geo_s2indexoldformat.js @@ -1,6 +1,6 @@ // Make sure that the 2dsphere index can deal with non-GeoJSON points. // 2dsphere does not accept legacy shapes, only legacy points. -t = db.geo_s2indexoldformat; +let t = db.geo_s2indexoldformat; t.drop(); t.insert({geo: [40, 5], nonGeo: ["pointA"]}); @@ -11,7 +11,7 @@ t.insert({geo: {x: 40.6, y: 5.4}}); t.createIndex({geo: "2dsphere", nonGeo: 1}); -res = t.find({"geo": {"$geoIntersects": {"$geometry": {x: 40, y: 5}}}}); +let res = t.find({"geo": {"$geoIntersects": {"$geometry": {x: 40, y: 5}}}}); assert.eq(res.count(), 1); res = t.find({"geo": {"$geoIntersects": {"$geometry": [41, 6]}}}); diff --git a/jstests/core/index/geo/geo_s2largewithin.js b/jstests/core/index/geo/geo_s2largewithin.js index e1eed8a2e6a..d94ebc5f0a7 100644 --- a/jstests/core/index/geo/geo_s2largewithin.js +++ b/jstests/core/index/geo/geo_s2largewithin.js @@ -1,20 +1,17 @@ // If our $within is enormous, create a coarse covering for the search so it // doesn't take forever. -t = db.geo_s2largewithin; +let t = db.geo_s2largewithin; t.drop(); t.createIndex({geo: "2dsphere"}); -testPoint = { - name: "origin", - geo: {type: "Point", coordinates: [0.0, 0.0]} -}; +let testPoint = {name: "origin", geo: {type: "Point", coordinates: [0.0, 0.0]}}; -testHorizLine = { +let testHorizLine = { name: "horiz", geo: {type: "LineString", coordinates: [[-2.0, 10.0], [2.0, 10.0]]} }; -testVertLine = { +let testVertLine = { name: "vert", geo: {type: "LineString", coordinates: [[10.0, -2.0], [10.0, 2.0]]} }; @@ -25,12 +22,12 @@ t.insert(testVertLine); // Test a poly that runs horizontally along the equator. -longPoly = { +let longPoly = { type: "Polygon", coordinates: [[[30.0, 1.0], [-30.0, 1.0], [-30.0, -1.0], [30.0, -1.0], [30.0, 1.0]]] }; -result = t.find({geo: {$geoWithin: {$geometry: longPoly}}}); +let result = t.find({geo: {$geoWithin: {$geometry: longPoly}}}); assert.eq(result.itcount(), 1); result = t.find({geo: {$geoWithin: {$geometry: longPoly}}}); assert.eq("origin", result[0].name); diff --git a/jstests/core/index/geo/geo_s2meridian.js b/jstests/core/index/geo/geo_s2meridian.js index 99eb0c63dc4..a0196bb5a41 100644 --- a/jstests/core/index/geo/geo_s2meridian.js +++ b/jstests/core/index/geo/geo_s2meridian.js @@ -1,4 +1,4 @@ -t = db.geo_s2meridian; +let t = db.geo_s2meridian; t.drop(); t.createIndex({geo: "2dsphere"}); @@ -8,18 +8,15 @@ t.createIndex({geo: "2dsphere"}); * that runs along the meridian. */ -meridianCrossingLine = { +let meridianCrossingLine = { geo: {type: "LineString", coordinates: [[-178.0, 10.0], [178.0, 10.0]]} }; assert.commandWorked(t.insert(meridianCrossingLine)); -lineAlongMeridian = { - type: "LineString", - coordinates: [[180.0, 11.0], [180.0, 9.0]] -}; +let lineAlongMeridian = {type: "LineString", coordinates: [[180.0, 11.0], [180.0, 9.0]]}; -result = t.find({geo: {$geoIntersects: {$geometry: lineAlongMeridian}}}); +let result = t.find({geo: {$geoIntersects: {$geometry: lineAlongMeridian}}}); assert.eq(result.itcount(), 1); t.drop(); @@ -29,21 +26,15 @@ t.createIndex({geo: "2dsphere"}); * on the meridian, and immediately on either side, and confirm that a poly * covering all of them returns them all. */ -pointOnNegativeSideOfMeridian = { - geo: {type: "Point", coordinates: [-179.0, 1.0]} -}; -pointOnMeridian = { - geo: {type: "Point", coordinates: [180.0, 1.0]} -}; -pointOnPositiveSideOfMeridian = { - geo: {type: "Point", coordinates: [179.0, 1.0]} -}; +let pointOnNegativeSideOfMeridian = {geo: {type: "Point", coordinates: [-179.0, 1.0]}}; +let pointOnMeridian = {geo: {type: "Point", coordinates: [180.0, 1.0]}}; +let pointOnPositiveSideOfMeridian = {geo: {type: "Point", coordinates: [179.0, 1.0]}}; t.insert(pointOnMeridian); t.insert(pointOnNegativeSideOfMeridian); t.insert(pointOnPositiveSideOfMeridian); -meridianCrossingPoly = { +let meridianCrossingPoly = { type: "Polygon", coordinates: [[[-178.0, 10.0], [178.0, 10.0], [178.0, -10.0], [-178.0, -10.0], [-178.0, 10.0]]] }; @@ -58,15 +49,9 @@ t.createIndex({geo: "2dsphere"}); * closer, but across the meridian, and confirm they both come back, and * that the order is correct. */ -pointOnNegativeSideOfMerid = { - name: "closer", - geo: {type: "Point", coordinates: [-179.0, 0.0]} -}; +let pointOnNegativeSideOfMerid = {name: "closer", geo: {type: "Point", coordinates: [-179.0, 0.0]}}; -pointOnPositiveSideOfMerid = { - name: "farther", - geo: {type: "Point", coordinates: [176.0, 0.0]} -}; +let pointOnPositiveSideOfMerid = {name: "farther", geo: {type: "Point", coordinates: [176.0, 0.0]}}; t.insert(pointOnNegativeSideOfMerid); t.insert(pointOnPositiveSideOfMerid); diff --git a/jstests/core/index/geo/geo_s2multi.js b/jstests/core/index/geo/geo_s2multi.js index 858dfd1efa1..3da229ad743 100644 --- a/jstests/core/index/geo/geo_s2multi.js +++ b/jstests/core/index/geo/geo_s2multi.js @@ -1,22 +1,19 @@ -t = db.geo_s2multi; +let t = db.geo_s2multi; t.drop(); t.createIndex({geo: "2dsphere"}); // Let's try the examples in the GeoJSON spec. -multiPointA = { - "type": "MultiPoint", - "coordinates": [[100.0, 0.0], [101.0, 1.0]] -}; +let multiPointA = {"type": "MultiPoint", "coordinates": [[100.0, 0.0], [101.0, 1.0]]}; assert.commandWorked(t.insert({geo: multiPointA})); -multiLineStringA = { +let multiLineStringA = { "type": "MultiLineString", "coordinates": [[[100.0, 0.0], [101.0, 1.0]], [[102.0, 2.0], [103.0, 3.0]]] }; assert.commandWorked(t.insert({geo: multiLineStringA})); -multiPolygonA = { +let multiPolygonA = { "type": "MultiPolygon", "coordinates": [ [[[102.0, 2.0], [103.0, 2.0], [103.0, 3.0], [102.0, 3.0], [102.0, 2.0]]], @@ -61,7 +58,7 @@ assert.eq( // Polygon contains itself and the multipoint. assert.eq(2, t.find({geo: {$geoWithin: {$geometry: multiPolygonA}}}).itcount()); -partialPolygonA = { +let partialPolygonA = { "type": "Polygon", "coordinates": [[[102.0, 2.0], [103.0, 2.0], [103.0, 3.0], [102.0, 3.0], [102.0, 2.0]]] }; diff --git a/jstests/core/index/geo/geo_s2near.js b/jstests/core/index/geo/geo_s2near.js index 2cd732da67a..7c584992e8a 100644 --- a/jstests/core/index/geo/geo_s2near.js +++ b/jstests/core/index/geo/geo_s2near.js @@ -4,17 +4,14 @@ // Test 2dsphere near search, called via find and $geoNear. (function() { -t = db.geo_s2near; +let t = db.geo_s2near; t.drop(); // Make sure that geoNear gives us back loc -goldenPoint = { - type: "Point", - coordinates: [31.0, 41.0] -}; +let goldenPoint = {type: "Point", coordinates: [31.0, 41.0]}; t.insert({geo: goldenPoint}); t.createIndex({geo: "2dsphere"}); -resNear = +let resNear = t.aggregate([ {$geoNear: {near: [30, 40], distanceField: "d", spherical: true, includeLocs: "loc"}}, {$limit: 1} @@ -25,31 +22,22 @@ assert.eq(resNear[0].loc, goldenPoint); // FYI: // One degree of long @ 0 is 111km or so. // One degree of lat @ 0 is 110km or so. -lat = 0; -lng = 0; -points = 10; +let lat = 0; +let lng = 0; +let points = 10; for (var x = -points; x < points; x += 1) { for (var y = -points; y < points; y += 1) { t.insert({geo: {"type": "Point", "coordinates": [lng + x / 1000.0, lat + y / 1000.0]}}); } } -origin = { - "type": "Point", - "coordinates": [lng, lat] -}; +let origin = {"type": "Point", "coordinates": [lng, lat]}; t.createIndex({geo: "2dsphere"}); // Near only works when the query is a point. -someline = { - "type": "LineString", - "coordinates": [[40, 5], [41, 6]] -}; -somepoly = { - "type": "Polygon", - "coordinates": [[[40, 5], [40, 6], [41, 6], [41, 5], [40, 5]]] -}; +let someline = {"type": "LineString", "coordinates": [[40, 5], [41, 6]]}; +let somepoly = {"type": "Polygon", "coordinates": [[[40, 5], [40, 6], [41, 6], [41, 5], [40, 5]]]}; assert.throws(function() { return t.find({"geo": {"$near": {"$geometry": someline}}}).count(); }); @@ -70,7 +58,7 @@ assert.commandFailedWithCode(db.runCommand({ 2); // Do some basic near searches. -res = t.find({"geo": {"$near": {"$geometry": origin, $maxDistance: 2000}}}).limit(10); +let res = t.find({"geo": {"$near": {"$geometry": origin, $maxDistance: 2000}}}).limit(10); resNear = t.aggregate([ {$geoNear: {near: [0, 0], distanceField: "dis", maxDistance: Math.PI, spherical: true}}, {$limit: 10}, @@ -109,29 +97,30 @@ assert.eq(res.itcount(), resNear.itcount(), ((2 * points) * (2 * points) + 4).to function testRadAndDegreesOK(distance) { // Distance for old style points is radians. - resRadians = t.find({geo: {$nearSphere: [0, 0], $maxDistance: (distance / (6378.1 * 1000))}}); + let resRadians = + t.find({geo: {$nearSphere: [0, 0], $maxDistance: (distance / (6378.1 * 1000))}}); // Distance for new style points is meters. - resMeters = t.find({"geo": {"$near": {"$geometry": origin, $maxDistance: distance}}}); + let resMeters = t.find({"geo": {"$near": {"$geometry": origin, $maxDistance: distance}}}); // And we should get the same # of results no matter what. assert.eq(resRadians.itcount(), resMeters.itcount()); // Also, $geoNear should behave the same way. - resGNMeters = t.aggregate({ - $geoNear: { - near: origin, - distanceField: "dis", - maxDistance: distance, - spherical: true, - } - }).toArray(); - resGNRadians = t.aggregate({ - $geoNear: { - near: [0, 0], - distanceField: "dis", - maxDistance: (distance / (6378.1 * 1000)), - spherical: true, - } - }).toArray(); + let resGNMeters = t.aggregate({ + $geoNear: { + near: origin, + distanceField: "dis", + maxDistance: distance, + spherical: true, + } + }).toArray(); + let resGNRadians = t.aggregate({ + $geoNear: { + near: [0, 0], + distanceField: "dis", + maxDistance: (distance / (6378.1 * 1000)), + spherical: true, + } + }).toArray(); const errmsg = `$geoNear using meter distances returned ${tojson(resGNMeters)}, but ` + `$geoNear using radian distances returned ${tojson(resGNRadians)}`; assert.eq(resGNRadians.length, resGNMeters.length, errmsg); diff --git a/jstests/core/index/geo/geo_s2nearComplex.js b/jstests/core/index/geo/geo_s2nearComplex.js index 22fe3112499..df978d45e61 100644 --- a/jstests/core/index/geo/geo_s2nearComplex.js +++ b/jstests/core/index/geo/geo_s2nearComplex.js @@ -18,7 +18,7 @@ var atan2 = Math.atan2; var originGeo = {type: "Point", coordinates: [20.0, 20.0]}; // Center point for all tests. -var origin = {name: "origin", geo: originGeo}; +let origin = {name: "origin", geo: originGeo}; /* * Convenience function for checking that coordinates match. threshold let's you @@ -114,7 +114,7 @@ function uniformPointsWithClusters( origin, count, minDist, maxDist, numberOfClusters, minClusterSize, maxClusterSize, distRatio) { distRatio = distRatio || 10; var points = uniformPoints(origin, count, minDist, maxDist); - for (j = 0; j < numberOfClusters; j++) { + for (let j = 0; j < numberOfClusters; j++) { var randomPoint = points[Math.floor(random() * points.length)]; var clusterSize = (random() * (maxClusterSize - minClusterSize)) + minClusterSize; uniformPoints(randomPoint, clusterSize, minDist / distRatio, maxDist / distRatio); @@ -146,18 +146,18 @@ function validateOrdering(query) { var near30 = t.find(query).limit(30); var near40 = t.find(query).limit(40); - for (i = 0; i < 10; i++) { + for (let i = 0; i < 10; i++) { assert(coordinateEqual(near10[i], near20[i])); assert(coordinateEqual(near10[i], near30[i])); assert(coordinateEqual(near10[i], near40[i])); } - for (i = 0; i < 20; i++) { + for (let i = 0; i < 20; i++) { assert(coordinateEqual(near20[i], near30[i])); assert(coordinateEqual(near20[i], near40[i])); } - for (i = 0; i < 30; i++) { + for (let i = 0; i < 30; i++) { assert(coordinateEqual(near30[i], near40[i])); } } @@ -281,7 +281,7 @@ origin = { uniformPoints(origin, 10, 89, 90); -cur = t.find({geo: {$near: {$geometry: originGeo}}}); +let cur = t.find({geo: {$near: {$geometry: originGeo}}}); assert.eq(cur.itcount(), 10); cur = t.find({geo: {$near: {$geometry: originGeo}}}); @@ -290,5 +290,5 @@ print("Near search on very distant points:"); print(t.find({geo: {$geoNear: {$geometry: originGeo}}}) .explain("executionStats") .executionStats.executionTimeMillis); -pt = cur.next(); +let pt = cur.next(); assert(pt); diff --git a/jstests/core/index/geo/geo_s2nearcorrect.js b/jstests/core/index/geo/geo_s2nearcorrect.js index 80ece4223d2..b21782140be 100644 --- a/jstests/core/index/geo/geo_s2nearcorrect.js +++ b/jstests/core/index/geo/geo_s2nearcorrect.js @@ -2,17 +2,11 @@ // A geometry may have several covers, one of which is in a search ring and the other of which is // not. If we see the cover that's not in the search ring, we can't mark the object as 'seen' for // this ring. -t = db.geo_s2nearcorrect; +let t = db.geo_s2nearcorrect; t.drop(); -longline = { - "type": "LineString", - "coordinates": [[0, 0], [179, 89]] -}; +let longline = {"type": "LineString", "coordinates": [[0, 0], [179, 89]]}; t.insert({geo: longline}); t.createIndex({geo: "2dsphere"}); -origin = { - "type": "Point", - "coordinates": [45, 45] -}; +let origin = {"type": "Point", "coordinates": [45, 45]}; assert.eq(1, t.find({"geo": {"$near": {"$geometry": origin, $maxDistance: 20000000}}}).count()); diff --git a/jstests/core/index/geo/geo_s2nongeoarray.js b/jstests/core/index/geo/geo_s2nongeoarray.js index f5830e8702d..3e2b0d5eb52 100644 --- a/jstests/core/index/geo/geo_s2nongeoarray.js +++ b/jstests/core/index/geo/geo_s2nongeoarray.js @@ -1,8 +1,8 @@ // Explode arrays when indexing non-geo fields in 2dsphere, and make sure that // we find them with queries. -t = db.geo_s2nongeoarray; +let t = db.geo_s2nongeoarray; -oldPoint = [40, 5]; +let oldPoint = [40, 5]; var data = {geo: oldPoint, nonGeo: [123, 456], otherNonGeo: [{b: [1, 2]}, {b: [3, 4]}]}; diff --git a/jstests/core/index/geo/geo_s2nonstring.js b/jstests/core/index/geo/geo_s2nonstring.js index a76a7cd073e..b7f9496a3b9 100644 --- a/jstests/core/index/geo/geo_s2nonstring.js +++ b/jstests/core/index/geo/geo_s2nonstring.js @@ -1,5 +1,5 @@ // Added to make sure that S2 indexing's string AND non-string keys work. -t = db.geo_s2nonstring; +let t = db.geo_s2nonstring; t.drop(); t.createIndex({geo: '2dsphere', x: 1}); diff --git a/jstests/core/index/geo/geo_s2nopoints.js b/jstests/core/index/geo/geo_s2nopoints.js index 7b3a3b970a7..b27c2ea2034 100644 --- a/jstests/core/index/geo/geo_s2nopoints.js +++ b/jstests/core/index/geo/geo_s2nopoints.js @@ -1,5 +1,5 @@ // See SERVER-7794. -t = db.geo_s2nopoints; +let t = db.geo_s2nopoints; t.drop(); t.createIndex({loc: "2dsphere", x: 1}); diff --git a/jstests/core/index/geo/geo_s2oddshapes.js b/jstests/core/index/geo/geo_s2oddshapes.js index db30d431caa..e6610dea12a 100644 --- a/jstests/core/index/geo/geo_s2oddshapes.js +++ b/jstests/core/index/geo/geo_s2oddshapes.js @@ -96,7 +96,7 @@ outsidePoint = { t.insert(insidePoint); t.insert(outsidePoint); -smallPoly = { +let smallPoly = { type: "Polygon", coordinates: [[[0.0, -0.01], [0.015, -0.01], [0.015, 0.01], [0.0, 0.01], [0.0, -0.01]]] }; diff --git a/jstests/core/index/geo/geo_s2twofields.js b/jstests/core/index/geo/geo_s2twofields.js index 9f769f6897f..af7f07f64eb 100644 --- a/jstests/core/index/geo/geo_s2twofields.js +++ b/jstests/core/index/geo/geo_s2twofields.js @@ -33,7 +33,7 @@ for (var i = 0; i < maxPoints; ++i) { arr.push( {from: {type: "Point", coordinates: fromCoord}, to: {type: "Point", coordinates: toCoord}}); } -res = t.insert(arr); +let res = t.insert(arr); assert.commandWorked(res); assert.eq(t.count(), maxPoints); diff --git a/jstests/core/index/geo/geo_s2within.js b/jstests/core/index/geo/geo_s2within.js index 04915c77dcb..6950cb3e482 100644 --- a/jstests/core/index/geo/geo_s2within.js +++ b/jstests/core/index/geo/geo_s2within.js @@ -1,18 +1,15 @@ // Test some cases that might be iffy with $within, mostly related to polygon w/holes. -t = db.geo_s2within; +let t = db.geo_s2within; t.drop(); t.createIndex({geo: "2dsphere"}); -somepoly = { - "type": "Polygon", - "coordinates": [[[40, 5], [40, 6], [41, 6], [41, 5], [40, 5]]] -}; +let somepoly = {"type": "Polygon", "coordinates": [[[40, 5], [40, 6], [41, 6], [41, 5], [40, 5]]]}; t.insert({geo: {"type": "LineString", "coordinates": [[40.1, 5.1], [40.2, 5.2]]}}); // This is only partially contained within the polygon. t.insert({geo: {"type": "LineString", "coordinates": [[40.1, 5.1], [42, 7]]}}); -res = t.find({"geo": {"$within": {"$geometry": somepoly}}}); +let res = t.find({"geo": {"$within": {"$geometry": somepoly}}}); assert.eq(res.itcount(), 1); t.drop(); diff --git a/jstests/core/index/geo/geo_sort1.js b/jstests/core/index/geo/geo_sort1.js index 4d32c2f4ae2..5f90ea50d60 100644 --- a/jstests/core/index/geo/geo_sort1.js +++ b/jstests/core/index/geo/geo_sort1.js @@ -1,21 +1,21 @@ -t = db.geo_sort1; +let t = db.geo_sort1; t.drop(); -for (x = 0; x < 10; x++) { - for (y = 0; y < 10; y++) { +for (let x = 0; x < 10; x++) { + for (let y = 0; y < 10; y++) { t.insert({loc: [x, y], foo: x * x * y}); } } t.createIndex({loc: "2d", foo: 1}); -q = t.find({loc: {$near: [5, 5]}, foo: {$gt: 20}}); -m = function(z) { +let q = t.find({loc: {$near: [5, 5]}, foo: {$gt: 20}}); +let m = function(z) { return z.foo; }; -a = q.clone().map(m); -b = q.clone().sort({foo: 1}).map(m); +let a = q.clone().map(m); +let b = q.clone().sort({foo: 1}).map(m); assert.neq(a, b, "A"); a.sort(); diff --git a/jstests/core/index/geo/geo_uniqueDocs.js b/jstests/core/index/geo/geo_uniqueDocs.js index 9e0a811e7e7..418f48691ed 100644 --- a/jstests/core/index/geo/geo_uniqueDocs.js +++ b/jstests/core/index/geo/geo_uniqueDocs.js @@ -1,8 +1,8 @@ // Test uniqueDocs option for $within queries and the $geoNear aggregation stage. SERVER-3139 // SERVER-12120 uniqueDocs is deprecated. Server always returns unique documents. -collName = 'geo_uniqueDocs_test'; -t = db.geo_uniqueDocs_test; +let collName = 'geo_uniqueDocs_test'; +let t = db.geo_uniqueDocs_test; t.drop(); assert.commandWorked(t.save({locs: [[0, 2], [3, 4]]})); @@ -21,7 +21,8 @@ assert.eq(2, t.aggregate({$geoNear: {near: [0, 0], distanceField: "dis", uniqueDocs: true}}) .toArray() .length); -results = t.aggregate([{$geoNear: {near: [0, 0], distanceField: "dis"}}, {$limit: 2}]).toArray(); +let results = + t.aggregate([{$geoNear: {near: [0, 0], distanceField: "dis"}}, {$limit: 2}]).toArray(); assert.eq(2, results.length); assert.close(2, results[0].dis); assert.close(10, results[1].dis); diff --git a/jstests/core/index/geo/geo_update1.js b/jstests/core/index/geo/geo_update1.js index f982966afd7..67b40a66ffb 100644 --- a/jstests/core/index/geo/geo_update1.js +++ b/jstests/core/index/geo/geo_update1.js @@ -3,7 +3,7 @@ // requires_non_retryable_writes, // ] -t = db.geo_update1; +let t = db.geo_update1; t.drop(); for (var x = 0; x < 10; x++) { diff --git a/jstests/core/index/geo/geo_update2.js b/jstests/core/index/geo/geo_update2.js index 280023ffe44..4073a5ccd9c 100644 --- a/jstests/core/index/geo/geo_update2.js +++ b/jstests/core/index/geo/geo_update2.js @@ -3,7 +3,7 @@ // requires_non_retryable_writes, // ] -t = db.geo_update2; +let t = db.geo_update2; t.drop(); for (var x = 0; x < 10; x++) { diff --git a/jstests/core/index/geo/geo_update_btree.js b/jstests/core/index/geo/geo_update_btree.js index 7a58362fe18..403af8e5f0c 100644 --- a/jstests/core/index/geo/geo_update_btree.js +++ b/jstests/core/index/geo/geo_update_btree.js @@ -27,7 +27,7 @@ var parallelInsert = startParallelShell( " db.jstests_geo_update_btree.insert(doc);" + "}"); -for (i = 0; i < 1000; i++) { +for (let i = 0; i < 1000; i++) { coll.update({ loc: {$within: {$center: [[Random.rand() * 180, Random.rand() * 180], Random.rand() * 50]}} }, diff --git a/jstests/core/index/geo/geo_withinquery.js b/jstests/core/index/geo/geo_withinquery.js index 13f20c1433f..c4069d93f4d 100644 --- a/jstests/core/index/geo/geo_withinquery.js +++ b/jstests/core/index/geo/geo_withinquery.js @@ -3,13 +3,13 @@ // ] // SERVER-7343: allow $within without a geo index. -t = db.geo_withinquery; +let t = db.geo_withinquery; t.drop(); -num = 0; -for (x = 0; x <= 20; x++) { - for (y = 0; y <= 20; y++) { - o = {_id: num++, loc: [x, y]}; +let num = 0; +for (let x = 0; x <= 20; x++) { + for (let y = 0; y <= 20; y++) { + let o = {_id: num++, loc: [x, y]}; t.save(o); } } diff --git a/jstests/core/index/geo/geoa.js b/jstests/core/index/geo/geoa.js index 78cf6c960c9..26bfc10b8cf 100644 --- a/jstests/core/index/geo/geoa.js +++ b/jstests/core/index/geo/geoa.js @@ -1,4 +1,4 @@ -t = db.geoa; +let t = db.geoa; t.drop(); t.save({_id: 1, a: {loc: [5, 5]}}); @@ -7,5 +7,5 @@ t.save({_id: 3, a: {loc: [7, 7]}}); t.createIndex({"a.loc": "2d"}); -cur = t.find({"a.loc": {$near: [6, 6]}}); +let cur = t.find({"a.loc": {$near: [6, 6]}}); assert.eq(2, cur.next()._id, "A1"); diff --git a/jstests/core/index/geo/geoc.js b/jstests/core/index/geo/geoc.js index 8875cd44614..5d8752b95a3 100644 --- a/jstests/core/index/geo/geoc.js +++ b/jstests/core/index/geo/geoc.js @@ -2,10 +2,10 @@ // requires_getmore, // ] -t = db.geoc; +let t = db.geoc; t.drop(); -N = 1000; +let N = 1000; for (var i = 0; i < N; i++) t.insert({loc: [100 + Math.random(), 100 + Math.random()], z: 0}); diff --git a/jstests/core/index/geo/geod.js b/jstests/core/index/geo/geod.js index 8586d64e398..27272929f65 100644 --- a/jstests/core/index/geo/geod.js +++ b/jstests/core/index/geo/geod.js @@ -5,13 +5,13 @@ t.save({loc: [0.5, 0]}); t.createIndex({loc: "2d"}); // do a few geoNears with different maxDistances. The first iteration // should match no points in the dataset. -dists = [.49, .51, 1.0]; -for (idx in dists) { - b = db.geod - .aggregate([ - {$geoNear: {near: [1, 0], distanceField: "d", maxDistance: dists[idx]}}, - {$limit: 2}, - ]) - .toArray(); +let dists = [.49, .51, 1.0]; +for (let idx in dists) { + let b = db.geod + .aggregate([ + {$geoNear: {near: [1, 0], distanceField: "d", maxDistance: dists[idx]}}, + {$limit: 2}, + ]) + .toArray(); assert.eq(b.length, idx, "B" + idx); } diff --git a/jstests/core/index/geo/geoe.js b/jstests/core/index/geo/geoe.js index 84bc34f7a74..eac049e0574 100644 --- a/jstests/core/index/geo/geoe.js +++ b/jstests/core/index/geo/geoe.js @@ -4,7 +4,7 @@ // the end of the btree and not reverse direction (leaving the rest of // the search always looking at some random non-matching point). -t = db.geo_box; +let t = db.geo_box; t.drop(); t.insert({"_id": 1, "geo": [33, -11.1]}); @@ -24,7 +24,7 @@ t.insert({"_id": 14, "geo": [-122.289505, 37.695774]}); t.createIndex({geo: "2d"}); -c = t.find({geo: {"$within": {"$box": [[-125.078461, 36.494473], [-120.320648, 38.905199]]}}}); +let c = t.find({geo: {"$within": {"$box": [[-125.078461, 36.494473], [-120.320648, 38.905199]]}}}); assert.eq(11, c.count(), "A1"); c = t.find({geo: {"$within": {"$box": [[-124.078461, 36.494473], [-120.320648, 38.905199]]}}}); diff --git a/jstests/core/index/geo/geof.js b/jstests/core/index/geo/geof.js index 1f1d9e0cc67..8dce3f68b6f 100644 --- a/jstests/core/index/geo/geof.js +++ b/jstests/core/index/geo/geof.js @@ -1,4 +1,4 @@ -t = db.geof; +let t = db.geof; t.drop(); // corners (dist ~0.98) diff --git a/jstests/core/index/index1.js b/jstests/core/index/index1.js index 4c06bfe03fd..e3805a6d4e8 100644 --- a/jstests/core/index/index1.js +++ b/jstests/core/index/index1.js @@ -1,13 +1,10 @@ // @tags: [requires_non_retryable_writes] -t = db.embeddedIndexTest; +let t = db.embeddedIndexTest; t.remove({}); -o = { - name: "foo", - z: {a: 17, b: 4} -}; +let o = {name: "foo", z: {a: 17, b: 4}}; t.save(o); assert(t.findOne().z.a == 17); diff --git a/jstests/core/index/index13.js b/jstests/core/index/index13.js index 97a3a85f773..ff2cb55332e 100644 --- a/jstests/core/index/index13.js +++ b/jstests/core/index/index13.js @@ -21,7 +21,7 @@ // SERVER-3104 implementation, the index constraints become [3,3] on the 'a.b' field _and_ [3,3] on // the 'a.c' field. -t = db.jstests_index13; +let t = db.jstests_index13; t.drop(); function assertConsistentResults(query) { @@ -30,16 +30,13 @@ function assertConsistentResults(query) { } function assertResults(query) { - explain = t.find(query).hint(index).explain(); + let explain = t.find(query).hint(index).explain(); // printjson( explain ); // debug assertConsistentResults(query); } // Cases with single dotted index fied names. -index = { - 'a.b': 1, - 'a.c': 1 -}; +let index = {'a.b': 1, 'a.c': 1}; t.createIndex(index); t.save({a: [{b: 1}, {c: 1}]}); t.save({a: [{b: 1, c: 1}]}); diff --git a/jstests/core/index/index4.js b/jstests/core/index/index4.js index 179bcdd9726..d5771862131 100644 --- a/jstests/core/index/index4.js +++ b/jstests/core/index/index4.js @@ -6,7 +6,7 @@ // index4.js -t = db.index4; +let t = db.index4; t.drop(); t.save({name: "alleyinsider", instances: [{pool: "prod1"}, {pool: "dev1"}]}); @@ -21,7 +21,7 @@ t.createIndex({"instances.pool": 1}); sleep(10); -a = t.find({instances: {pool: "prod1"}}); +let a = t.find({instances: {pool: "prod1"}}); assert(a.length() == 1, "len1"); assert(a[0].name == "alleyinsider", "alley"); diff --git a/jstests/core/index/index5.js b/jstests/core/index/index5.js index 908b433c299..8175d5bcc54 100644 --- a/jstests/core/index/index5.js +++ b/jstests/core/index/index5.js @@ -4,17 +4,17 @@ function validate() { assert.eq(2, t.find().count()); - f = t.find().sort({a: 1}); + let f = t.find().sort({a: 1}); assert.eq(2, t.count()); assert.eq(1, f[0].a); assert.eq(2, f[1].a); - r = t.find().sort({a: -1}); + let r = t.find().sort({a: -1}); assert.eq(2, r.count()); assert.eq(2, r[0].a); assert.eq(1, r[1].a); } -t = db.index5; +let t = db.index5; t.drop(); t.save({a: 1}); diff --git a/jstests/core/index/index6.js b/jstests/core/index/index6.js index 4626e9359ea..3edefedfc1b 100644 --- a/jstests/core/index/index6.js +++ b/jstests/core/index/index6.js @@ -1,6 +1,6 @@ // index6.js Test indexes on array subelements. -r = db.ed.db.index6; +let r = db.ed.db.index6; r.drop(); r.save({comments: [{name: "eliot", foo: 1}]}); diff --git a/jstests/core/index/index8.js b/jstests/core/index/index8.js index 3887906dddc..2b62040ca50 100644 --- a/jstests/core/index/index8.js +++ b/jstests/core/index/index8.js @@ -12,14 +12,14 @@ // Test key uniqueness (function() { -t = db.jstests_index8; +let t = db.jstests_index8; t.drop(); t.createIndex({a: 1}); t.createIndex({b: 1}, true); t.createIndex({c: 1}, [false, "cIndex"]); -checkIndexes = function(num) { +let checkIndexes = function(num) { const indexes = t.getIndexes(); assert.eq(4, indexes.length); diff --git a/jstests/core/index/index9.js b/jstests/core/index/index9.js index 7bf7ec5ac43..ed7da662858 100644 --- a/jstests/core/index/index9.js +++ b/jstests/core/index/index9.js @@ -2,7 +2,7 @@ // expected. Also, the primary node cannot change because we use the local database in this test. // @tags: [assumes_no_implicit_collection_creation_after_drop, does_not_support_stepdowns] -t = db.jstests_index9; +let t = db.jstests_index9; t.drop(); assert.commandWorked(db.createCollection("jstests_index9")); diff --git a/jstests/core/index/index_arr1.js b/jstests/core/index/index_arr1.js index d6db3e621cd..749b54543d5 100644 --- a/jstests/core/index/index_arr1.js +++ b/jstests/core/index/index_arr1.js @@ -2,7 +2,7 @@ // collection. // @tags: [assumes_no_implicit_index_creation] -t = db.index_arr1; +let t = db.index_arr1; t.drop(); t.insert({_id: 1, a: 5, b: [{x: 1}]}); diff --git a/jstests/core/index/index_arr2.js b/jstests/core/index/index_arr2.js index 99950880422..ae977f5a514 100644 --- a/jstests/core/index/index_arr2.js +++ b/jstests/core/index/index_arr2.js @@ -1,27 +1,27 @@ // @tags: [assumes_balancer_off, requires_multi_updates, requires_non_retryable_writes] -NUM = 20; -M = 5; +let NUM = 20; +let M = 5; -t = db.jstests_arr2; +let t = db.jstests_arr2; function test(withIndex) { t.drop(); // insert a bunch of items to force queries to use the index. - newObject = {_id: 1, a: [{b: {c: 1}}]}; + let newObject = {_id: 1, a: [{b: {c: 1}}]}; - now = (new Date()).getTime() / 1000; - for (created = now - NUM; created <= now; created++) { + let now = (new Date()).getTime() / 1000; + for (let created = now - NUM; created <= now; created++) { newObject['created'] = created; t.insert(newObject); newObject['_id']++; } // change the last M items. - query = {'created': {'$gte': now - M}}; + let query = {'created': {'$gte': now - M}}; - Z = t.find(query).count(); + let Z = t.find(query).count(); if (withIndex) { // t.createIndex( { 'a.b.c' : 1, 'created' : -1 } ) @@ -35,7 +35,7 @@ function test(withIndex) { // now see how many were actually updated. query['a.b.c'] = 0; - count = t.count(query); + let count = t.count(query); assert.eq(Z, count, "count after withIndex:" + withIndex); } diff --git a/jstests/core/index/index_bounds_number_edge_cases.js b/jstests/core/index/index_bounds_number_edge_cases.js index 3da4e53e2d0..6f08c663246 100644 --- a/jstests/core/index/index_bounds_number_edge_cases.js +++ b/jstests/core/index/index_bounds_number_edge_cases.js @@ -2,7 +2,7 @@ // should handle numerical extremes // such as Number.MAX_VALUE and Infinity -t = db.indexboundsnumberedgecases; +let t = db.indexboundsnumberedgecases; t.drop(); diff --git a/jstests/core/index/index_check2.js b/jstests/core/index/index_check2.js index e296e3b558a..170c54a0322 100644 --- a/jstests/core/index/index_check2.js +++ b/jstests/core/index/index_check2.js @@ -3,7 +3,7 @@ // requires_getmore // ] -t = db.index_check2; +let t = db.index_check2; t.drop(); // Include helpers for analyzing explain output. @@ -17,15 +17,9 @@ for (var i = 0; i < 1000; i++) { t.save({num: i, tags: a}); } -q1 = { - tags: "tag6" -}; -q2 = { - tags: "tag12" -}; -q3 = { - tags: {$all: ["tag6", "tag12"]} -}; +let q1 = {tags: "tag6"}; +let q2 = {tags: "tag12"}; +let q3 = {tags: {$all: ["tag6", "tag12"]}}; assert.eq(120, t.find(q1).itcount(), "q1 a"); assert.eq(120, t.find(q2).itcount(), "q2 a"); @@ -42,9 +36,9 @@ assert(isIxscan(db, getWinningPlan(t.find(q1).explain().queryPlanner)), "e1"); assert(isIxscan(db, getWinningPlan(t.find(q2).explain().queryPlanner)), "e2"); assert(isIxscan(db, getWinningPlan(t.find(q3).explain().queryPlanner)), "e3"); -scanned1 = t.find(q1).explain("executionStats").executionStats.totalKeysExamined; -scanned2 = t.find(q2).explain("executionStats").executionStats.totalKeysExamined; -scanned3 = t.find(q3).explain("executionStats").executionStats.totalKeysExamined; +let scanned1 = t.find(q1).explain("executionStats").executionStats.totalKeysExamined; +let scanned2 = t.find(q2).explain("executionStats").executionStats.totalKeysExamined; +let scanned3 = t.find(q3).explain("executionStats").executionStats.totalKeysExamined; // print( "scanned1: " + scanned1 + " scanned2: " + scanned2 + " scanned3: " + scanned3 ); diff --git a/jstests/core/index/index_check5.js b/jstests/core/index/index_check5.js index 8921e014fcd..62f72c0e612 100644 --- a/jstests/core/index/index_check5.js +++ b/jstests/core/index/index_check5.js @@ -1,5 +1,5 @@ -t = db.index_check5; +let t = db.index_check5; t.drop(); t.save({ diff --git a/jstests/core/index/index_diag.js b/jstests/core/index/index_diag.js index 769e5575bf1..bb9cd4ed323 100644 --- a/jstests/core/index/index_diag.js +++ b/jstests/core/index/index_diag.js @@ -3,14 +3,14 @@ // ] load("jstests/libs/fixture_helpers.js"); -t = db.index_diag; +let t = db.index_diag; t.drop(); assert.commandWorked(t.createIndex({x: 1})); -all = []; -ids = []; -xs = []; +let all = []; +let ids = []; +let xs = []; function r(a) { var n = []; @@ -19,8 +19,8 @@ function r(a) { return n; } -for (i = 1; i < 4; i++) { - o = {_id: i, x: -i}; +for (let i = 1; i < 4; i++) { + let o = {_id: i, x: -i}; t.insert(o); all.push(o); ids.push({_id: i}); diff --git a/jstests/core/index/index_filter_commands.js b/jstests/core/index/index_filter_commands.js index 429a79adea8..dd60bfbc18c 100644 --- a/jstests/core/index/index_filter_commands.js +++ b/jstests/core/index/index_filter_commands.js @@ -187,7 +187,7 @@ assert.eq(null, planCacheEntryForQuery(shape), coll.getPlanCache().list()); // Check details of winning plan in plan cache after setting filter and re-executing query. assert.eq(1, coll.find(queryA1, projectionA1).sort(sortA1).itcount(), 'unexpected document count'); -planAfterSetFilter = planCacheEntryForQuery(shape); +let planAfterSetFilter = planCacheEntryForQuery(shape); assert.neq(null, planAfterSetFilter, coll.getPlanCache().list()); // Check 'indexFilterSet' field in plan details assert.eq(true, planAfterSetFilter.indexFilterSet, planAfterSetFilter); @@ -441,7 +441,7 @@ if (checkSBEEnabled(db)) { assert.eq(lookupStage.strategy, "IndexedLoopJoin", explain); assert.eq(lookupStage.indexName, "foreign_a_1"); - ixscanStage = getPlanStage(explain, "IXSCAN"); + let ixscanStage = getPlanStage(explain, "IXSCAN"); assert.neq(null, ixscanStage, explain); assert.eq(ixscanStage.indexName, "main_a_1_c_1", explain); diff --git a/jstests/core/index/index_many.js b/jstests/core/index/index_many.js index cdd559c9be5..ee1f71477c0 100644 --- a/jstests/core/index/index_many.js +++ b/jstests/core/index/index_many.js @@ -4,7 +4,7 @@ /* test using lots of indexes on one collection */ -t = db.many; +let t = db.many; function f() { t.drop(); @@ -13,10 +13,10 @@ function f() { t.save({x: 9, y: 99}); t.save({x: 19, y: 99}); - x = 2; + let x = 2; var lastErr = null; while (x < 70) { - patt = {}; + let patt = {}; patt[x] = 1; if (x == 20) patt = {x: 1}; @@ -29,7 +29,7 @@ function f() { assert.commandFailed(lastErr, "should have got an error 'too many indexes'"); // 40 is the limit currently - lim = t.getIndexes().length; + let lim = t.getIndexes().length; if (lim != 64) { print("# of indexes should be 64 but is : " + lim); return; diff --git a/jstests/core/index/index_sparse1.js b/jstests/core/index/index_sparse1.js index 58bc5baa9b8..0aec94e8ab2 100644 --- a/jstests/core/index/index_sparse1.js +++ b/jstests/core/index/index_sparse1.js @@ -2,7 +2,7 @@ // collection. // @tags: [assumes_no_implicit_index_creation, requires_non_retryable_writes, requires_fastcount] -t = db.index_sparse1; +let t = db.index_sparse1; t.drop(); t.insert({_id: 1, x: 1}); diff --git a/jstests/core/index/index_sparse2.js b/jstests/core/index/index_sparse2.js index 324b46d8216..c7a9b0fac04 100644 --- a/jstests/core/index/index_sparse2.js +++ b/jstests/core/index/index_sparse2.js @@ -2,7 +2,7 @@ // collection. // @tags: [assumes_no_implicit_index_creation, requires_fastcount] -t = db.index_sparse2; +let t = db.index_sparse2; t.drop(); t.insert({_id: 1, x: 1, y: 1}); diff --git a/jstests/core/index/indexa.js b/jstests/core/index/indexa.js index 01fde035621..937dde52df1 100644 --- a/jstests/core/index/indexa.js +++ b/jstests/core/index/indexa.js @@ -5,7 +5,7 @@ // unique index constraint test for updates // case where object doesn't grow tested here -t = db.indexa; +let t = db.indexa; t.drop(); t.createIndex({x: 1}, true); @@ -18,8 +18,8 @@ assert.eq(2, t.count(), "indexa 1"); t.update({x: 'B'}, {x: 'A'}); -a = t.find().toArray(); -u = Array.unique(a.map(function(z) { +let a = t.find().toArray(); +let u = Array.unique(a.map(function(z) { return z.x; })); assert.eq(2, t.count(), "indexa 2"); diff --git a/jstests/core/index/indexb.js b/jstests/core/index/indexb.js index 59546f7fae2..5c5177fd239 100644 --- a/jstests/core/index/indexb.js +++ b/jstests/core/index/indexb.js @@ -8,15 +8,13 @@ // see indexa.js for the test case for an update with dup id check // when it doesn't move -t = db.indexb; +let t = db.indexb; t.drop(); t.createIndex({a: 1}, true); t.insert({a: 1}); -x = { - a: 2 -}; +let x = {a: 2}; t.save(x); { diff --git a/jstests/core/index/indexc.js b/jstests/core/index/indexc.js index bf5735380fa..b65d5a6e891 100644 --- a/jstests/core/index/indexc.js +++ b/jstests/core/index/indexc.js @@ -1,5 +1,5 @@ -t = db.indexc; +let t = db.indexc; t.drop(); const startMillis = new Date().getTime(); @@ -7,7 +7,7 @@ for (var i = 1; i < 100; i++) { var d = new Date(startMillis + i); t.save({a: i, ts: d, cats: [i, i + 1, i + 2]}); if (i == 51) - mid = d; + var mid = d; } assert.eq(50, t.find({ts: {$lt: mid}}).itcount(), "A"); diff --git a/jstests/core/index/indexe.js b/jstests/core/index/indexe.js index a307882adc3..aaafc5bda3b 100644 --- a/jstests/core/index/indexe.js +++ b/jstests/core/index/indexe.js @@ -1,11 +1,11 @@ // @tags: [requires_getmore, requires_fastcount] -t = db.indexe; +let t = db.indexe; t.drop(); var num = 1000; -for (i = 0; i < num; i++) { +for (let i = 0; i < num; i++) { t.insert({a: "b"}); } diff --git a/jstests/core/index/indexf.js b/jstests/core/index/indexf.js index 37c27967229..8837b9e2571 100644 --- a/jstests/core/index/indexf.js +++ b/jstests/core/index/indexf.js @@ -1,5 +1,5 @@ -t = db.indexf; +let t = db.indexf; t.drop(); t.createIndex({x: 1}); diff --git a/jstests/core/index/indexg.js b/jstests/core/index/indexg.js index f8f466d6495..47f7a587d9e 100644 --- a/jstests/core/index/indexg.js +++ b/jstests/core/index/indexg.js @@ -1,10 +1,10 @@ -f = db.jstests_indexg; +let f = db.jstests_indexg; f.drop(); f.save({list: [1, 2]}); f.save({list: [1, 3]}); -doit = function() { +let doit = function() { assert.eq(1, f.count({list: {$in: [1], $ne: 3}})); assert.eq(1, f.count({list: {$in: [1], $not: {$in: [3]}}})); }; diff --git a/jstests/core/index/indexl.js b/jstests/core/index/indexl.js index d372c770574..d0ba873e437 100644 --- a/jstests/core/index/indexl.js +++ b/jstests/core/index/indexl.js @@ -1,6 +1,6 @@ // Check nonoverlapping $in/$all with multikeys SERVER-2165 -t = db.jstests_indexl; +let t = db.jstests_indexl; function test(t) { t.save({a: [1, 2]}); diff --git a/jstests/core/index/indexm.js b/jstests/core/index/indexm.js index 7613b125357..2fc04263273 100644 --- a/jstests/core/index/indexm.js +++ b/jstests/core/index/indexm.js @@ -1,6 +1,6 @@ // Check proper range combinations with or clauses overlapping non or portion of query SERVER-2302 -t = db.jstests_indexm; +let t = db.jstests_indexm; t.drop(); t.save({a: [{x: 1}, {x: 2}, {x: 3}, {x: 4}]}); diff --git a/jstests/core/index/indexn.js b/jstests/core/index/indexn.js index a292ae2e5d3..ddd7dc5169d 100644 --- a/jstests/core/index/indexn.js +++ b/jstests/core/index/indexn.js @@ -4,7 +4,7 @@ // assumes_read_concern_local, // ] -t = db.jstests_indexn; +let t = db.jstests_indexn; t.drop(); t.save({a: 1, b: [1, 2]}); diff --git a/jstests/core/index/indexr.js b/jstests/core/index/indexr.js index d3ff5f7e02e..a056d29281f 100644 --- a/jstests/core/index/indexr.js +++ b/jstests/core/index/indexr.js @@ -4,7 +4,7 @@ // Check multikey index cases with parallel nested fields SERVER-958. -t = db.jstests_indexr; +let t = db.jstests_indexr; t.drop(); // Check without indexes. diff --git a/jstests/core/index/indexs.js b/jstests/core/index/indexs.js index 6ee625071e2..6cbabbb8f82 100644 --- a/jstests/core/index/indexs.js +++ b/jstests/core/index/indexs.js @@ -1,7 +1,7 @@ // Test index key generation issue with parent and nested fields in same index and array containing // subobject SERVER-3005. -t = db.jstests_indexs; +let t = db.jstests_indexs; t.drop(); t.createIndex({a: 1}); diff --git a/jstests/core/index/indext.js b/jstests/core/index/indext.js index 1ac92d6be5d..13e0ce0fb57 100644 --- a/jstests/core/index/indext.js +++ b/jstests/core/index/indext.js @@ -1,6 +1,6 @@ // Sparse indexes with arrays SERVER-3216 -t = db.jstests_indext; +let t = db.jstests_indext; t.drop(); t.createIndex({'a.b': 1}, {sparse: true}); diff --git a/jstests/core/index/useindexonobjgtlt.js b/jstests/core/index/useindexonobjgtlt.js index 506618e16c6..bcdf36f3279 100644 --- a/jstests/core/index/useindexonobjgtlt.js +++ b/jstests/core/index/useindexonobjgtlt.js @@ -1,6 +1,6 @@ // @tags: [requires_fastcount] -t = db.factories; +let t = db.factories; t.drop(); t.insert({name: "xyz", metro: {city: "New York", state: "NY"}}); t.createIndex({metro: 1}); diff --git a/jstests/core/index/wildcard/compound_wildcard_index_hiding.js b/jstests/core/index/wildcard/compound_wildcard_index_hiding.js index a3e304bfc4b..903624d4273 100644 --- a/jstests/core/index/wildcard/compound_wildcard_index_hiding.js +++ b/jstests/core/index/wildcard/compound_wildcard_index_hiding.js @@ -51,17 +51,6 @@ const cwiList = [ }, ]; -function validateIndex(coll, indexSpec) { - const index = findIndex(coll, indexSpec); - assert.neq(null, index); - - if (indexSpec.hidden) { - assert.eq(true, index.hidden); - } else { - assert.neq(true, index.hidden); - } -} - function setIndexVisibilityByKeyPattern(collectionName, keyPattern, hidden) { assert.commandWorked(db.runCommand({collMod: collectionName, index: {keyPattern, hidden}})); } diff --git a/jstests/core/json1.js b/jstests/core/json1.js index 31b2794c9a9..fdcea151e05 100644 --- a/jstests/core/json1.js +++ b/jstests/core/json1.js @@ -1,8 +1,5 @@ -x = { - quotes: "a\"b", - nulls: null -}; +let x = {quotes: "a\"b", nulls: null}; eval("y = " + tojson(x)); assert.eq(tojson(x), tojson(y), "A"); assert.eq(typeof (x.nulls), typeof (y.nulls), "B"); diff --git a/jstests/core/json_schema/misc_validation.js b/jstests/core/json_schema/misc_validation.js index 4821c0643f9..76dec255711 100644 --- a/jstests/core/json_schema/misc_validation.js +++ b/jstests/core/json_schema/misc_validation.js @@ -38,8 +38,6 @@ assert.commandWorked(testDB.createCollection(testName)); const coll = testDB.getCollection(testName); coll.drop(); -const isMongos = (testDB.runCommand("hello").msg === "isdbgrid"); - // Test that $jsonSchema is rejected in an $elemMatch projection. assert.throws(function() { coll.find({}, {a: {$elemMatch: {$jsonSchema: {}}}}).itcount(); diff --git a/jstests/core/jssymbol.js b/jstests/core/jssymbol.js index 714ea48870a..9465b6774c0 100644 --- a/jstests/core/jssymbol.js +++ b/jstests/core/jssymbol.js @@ -16,9 +16,9 @@ assert(db[Symbol.species] != 1); assert(db[Symbol.toPrimitive] != 1); // Exercise Symbol.toPrimitive on BSON objects -col1 = db.jssymbol_col; +let col1 = db.jssymbol_col; col1.insert({}); -a = db.getCollection("jssymbol_col").getIndexes()[0]; +let a = db.getCollection("jssymbol_col").getIndexes()[0]; assert(isNaN(+a)); assert(+a.v >= 1); diff --git a/jstests/core/logprocessdetails.js b/jstests/core/logprocessdetails.js index 4c72f802262..fe9c8a99b1c 100644 --- a/jstests/core/logprocessdetails.js +++ b/jstests/core/logprocessdetails.js @@ -14,7 +14,7 @@ * Checks an array for match against regex. * Returns true if regex matches a string in the array */ -doesLogMatchRegex = function(logArray, regex) { +let doesLogMatchRegex = function(logArray, regex) { for (var i = (logArray.length - 1); i >= 0; i--) { var regexInLine = regex.exec(logArray[i]); if (regexInLine != null) { @@ -24,7 +24,7 @@ doesLogMatchRegex = function(logArray, regex) { return false; }; -doTest = function() { +let doTest = function() { var log = db.adminCommand({getLog: 'global'}); // this regex will need to change if output changes var re = new RegExp(".*conn.*options.*"); diff --git a/jstests/core/multi.js b/jstests/core/multi.js index ac961ed7a9c..58cb327f86f 100644 --- a/jstests/core/multi.js +++ b/jstests/core/multi.js @@ -1,4 +1,4 @@ -t = db.jstests_multi; +let t = db.jstests_multi; t.drop(); t.createIndex({a: 1}); diff --git a/jstests/core/multi2.js b/jstests/core/multi2.js index 64473e4de98..cf9dd924d51 100644 --- a/jstests/core/multi2.js +++ b/jstests/core/multi2.js @@ -1,6 +1,6 @@ // @tags: [requires_fastcount] -t = db.multi2; +let t = db.multi2; t.drop(); t.save({x: 1, a: [1]}); diff --git a/jstests/core/notablescan.js b/jstests/core/notablescan.js index f9addc78099..ff9a0b91f2d 100644 --- a/jstests/core/notablescan.js +++ b/jstests/core/notablescan.js @@ -16,7 +16,7 @@ // tenant_migration_incompatible, // ] -t = db.test_notablescan; +let t = db.test_notablescan; t.drop(); try { diff --git a/jstests/core/notablescan_capped.js b/jstests/core/notablescan_capped.js index cc7405ff88b..43ac4d43f94 100644 --- a/jstests/core/notablescan_capped.js +++ b/jstests/core/notablescan_capped.js @@ -17,14 +17,14 @@ // tenant_migration_incompatible, // ] -t = db.test_notablescan_capped; +let t = db.test_notablescan_capped; t.drop(); assert.commandWorked(db.createCollection(t.getName(), {capped: true, size: 100})); try { assert.commandWorked(db._adminCommand({setParameter: 1, notablescan: true})); - err = assert.throws(function() { + let err = assert.throws(function() { t.find({a: 1}).tailable(true).next(); }); assert.includes(err.toString(), "tailable"); diff --git a/jstests/core/operation_latency_histogram.js b/jstests/core/operation_latency_histogram.js index cd220deae48..703d5da8f6b 100644 --- a/jstests/core/operation_latency_histogram.js +++ b/jstests/core/operation_latency_histogram.js @@ -27,6 +27,7 @@ (function() { "use strict"; +load("jstests/libs/fixture_helpers.js"); load("jstests/libs/stats.js"); var name = "operationalLatencyHistogramTest"; @@ -145,8 +146,7 @@ lastHistogram = assertHistogramDiffEq(testColl, lastHistogram, 0, 0, 1); // Reindex (Only standalone mode supports the reIndex command.) const hello = db.runCommand({hello: 1}); -const isMongos = (hello.msg === "isdbgrid"); -const isStandalone = !isMongos && !hello.hasOwnProperty('setName'); +const isStandalone = !FixtureHelpers.isMongos(db) && !hello.hasOwnProperty('setName'); if (isStandalone) { assert.commandWorked(testColl.reIndex()); lastHistogram = assertHistogramDiffEq(testColl, lastHistogram, 0, 0, 1); diff --git a/jstests/core/query/all/all.js b/jstests/core/query/all/all.js index a718e2615e8..9132c6f7c51 100644 --- a/jstests/core/query/all/all.js +++ b/jstests/core/query/all/all.js @@ -1,7 +1,7 @@ -t = db.jstests_all; +let t = db.jstests_all; t.drop(); -doTest = function() { +let doTest = function() { assert.commandWorked(t.save({a: [1, 2, 3]})); assert.commandWorked(t.save({a: [1, 2, 4]})); assert.commandWorked(t.save({a: [1, 8, 5]})); diff --git a/jstests/core/query/all/all2.js b/jstests/core/query/all/all2.js index b0c6d40cf68..738b5f746d0 100644 --- a/jstests/core/query/all/all2.js +++ b/jstests/core/query/all/all2.js @@ -1,11 +1,11 @@ -t = db.all2; +let t = db.all2; t.drop(); t.save({a: [{x: 1}, {x: 2}]}); t.save({a: [{x: 2}, {x: 3}]}); t.save({a: [{x: 3}, {x: 4}]}); -state = "no index"; +let state = "no index"; function check(n, q, e) { assert.eq(n, t.find(q).count(), tojson(q) + " " + e + " count " + state); diff --git a/jstests/core/query/all/all3.js b/jstests/core/query/all/all3.js index 37cb6c690b2..ee14e3a1102 100644 --- a/jstests/core/query/all/all3.js +++ b/jstests/core/query/all/all3.js @@ -2,7 +2,7 @@ // Check that $all matching null is consistent with $in - SERVER-3820 -t = db.jstests_all3; +let t = db.jstests_all3; t.drop(); t.save({}); diff --git a/jstests/core/query/all/all4.js b/jstests/core/query/all/all4.js index eb979289496..d3486b467ad 100644 --- a/jstests/core/query/all/all4.js +++ b/jstests/core/query/all/all4.js @@ -1,6 +1,6 @@ // Test $all/$elemMatch with missing field - SERVER-4492 -t = db.jstests_all4; +let t = db.jstests_all4; t.drop(); function checkQuery(query, val) { diff --git a/jstests/core/query/all/all5.js b/jstests/core/query/all/all5.js index a5faaa1767f..ff14671d524 100644 --- a/jstests/core/query/all/all5.js +++ b/jstests/core/query/all/all5.js @@ -1,6 +1,6 @@ // Test $all/$elemMatch/null matching - SERVER-4517 -t = db.jstests_all5; +let t = db.jstests_all5; t.drop(); function checkMatch(doc) { diff --git a/jstests/core/query/and/and.js b/jstests/core/query/and/and.js index 20fd583c31f..c68f8381886 100644 --- a/jstests/core/query/and/and.js +++ b/jstests/core/query/and/and.js @@ -4,7 +4,7 @@ // requires_scripting // ] -t = db.jstests_and; +let t = db.jstests_and; t.drop(); t.save({a: [1, 2]}); diff --git a/jstests/core/query/and/and2.js b/jstests/core/query/and/and2.js index 5a946c2cb76..79d4fc590c4 100644 --- a/jstests/core/query/and/and2.js +++ b/jstests/core/query/and/and2.js @@ -5,7 +5,7 @@ // Test dollar sign operator with $and SERVER-1089 -t = db.jstests_and2; +let t = db.jstests_and2; t.drop(); t.save({a: [1, 2]}); diff --git a/jstests/core/query/and/and3.js b/jstests/core/query/and/and3.js index 5256237bc33..1dfecc87ffa 100644 --- a/jstests/core/query/and/and3.js +++ b/jstests/core/query/and/and3.js @@ -6,7 +6,7 @@ // assumes_read_concern_local, // ] -t = db.jstests_and3; +let t = db.jstests_and3; t.drop(); t.save({a: 1}); diff --git a/jstests/core/query/and/andor.js b/jstests/core/query/and/andor.js index 5bac12d83ca..b8ae2df86a9 100644 --- a/jstests/core/query/and/andor.js +++ b/jstests/core/query/and/andor.js @@ -1,6 +1,6 @@ // SERVER-1089 Test and/or/nor nesting -t = db.jstests_andor; +let t = db.jstests_andor; t.drop(); // not ok @@ -10,7 +10,7 @@ function ok(q) { t.save({a: 1}); -test = function() { +let test = function() { ok({a: 1}); ok({$and: [{a: 1}]}); diff --git a/jstests/core/query/array/array3.js b/jstests/core/query/array/array3.js index 42acdfb6d3e..16d03b880ed 100644 --- a/jstests/core/query/array/array3.js +++ b/jstests/core/query/array/array3.js @@ -2,6 +2,6 @@ assert.eq(5, Array.sum([1, 4]), "A"); assert.eq(2.5, Array.avg([1, 4]), "B"); -arr = [2, 4, 4, 4, 5, 5, 7, 9]; +let arr = [2, 4, 4, 4, 5, 5, 7, 9]; assert.eq(5, Array.avg(arr), "C"); assert.eq(2, Array.stdDev(arr), "D"); diff --git a/jstests/core/query/array/array_match1.js b/jstests/core/query/array/array_match1.js index 0c56e8d4c34..e21d0a9e7c9 100644 --- a/jstests/core/query/array/array_match1.js +++ b/jstests/core/query/array/array_match1.js @@ -1,4 +1,4 @@ -t = db.array_match1; +let t = db.array_match1; t.drop(); t.insert({_id: 1, a: [5, 5]}); diff --git a/jstests/core/query/array/array_match2.js b/jstests/core/query/array/array_match2.js index 3e0dde8f5f5..fa4034d5c3c 100644 --- a/jstests/core/query/array/array_match2.js +++ b/jstests/core/query/array/array_match2.js @@ -1,6 +1,6 @@ // @tags: [requires_non_retryable_writes] -t = db.jstests_array_match2; +let t = db.jstests_array_match2; t.drop(); t.save({a: [{1: 4}, 5]}); diff --git a/jstests/core/query/array/array_match3.js b/jstests/core/query/array/array_match3.js index 4990bdd90fd..ad362e5e43b 100644 --- a/jstests/core/query/array/array_match3.js +++ b/jstests/core/query/array/array_match3.js @@ -1,6 +1,6 @@ // SERVER-2902 Test indexing of numerically referenced array elements. -t = db.jstests_array_match3; +let t = db.jstests_array_match3; t.drop(); // Test matching numericallly referenced array element. diff --git a/jstests/core/query/array/arrayfind1.js b/jstests/core/query/array/arrayfind1.js index 4e9330549ae..b50ecae7809 100644 --- a/jstests/core/query/array/arrayfind1.js +++ b/jstests/core/query/array/arrayfind1.js @@ -2,7 +2,7 @@ // requires_fastcount, // ] -t = db.arrayfind1; +let t = db.arrayfind1; t.drop(); t.save({a: [{x: 1}]}); diff --git a/jstests/core/query/array/arrayfind2.js b/jstests/core/query/array/arrayfind2.js index 38de844f6f4..14eb2411e7c 100644 --- a/jstests/core/query/array/arrayfind2.js +++ b/jstests/core/query/array/arrayfind2.js @@ -1,6 +1,6 @@ // @tags: [requires_fastcount] -t = db.arrayfind2; +let t = db.arrayfind2; t.drop(); function go(prefix) { diff --git a/jstests/core/query/array/arrayfind3.js b/jstests/core/query/array/arrayfind3.js index 6dba0bf625f..619ed2e1046 100644 --- a/jstests/core/query/array/arrayfind3.js +++ b/jstests/core/query/array/arrayfind3.js @@ -1,4 +1,4 @@ -t = db.arrayfind3; +let t = db.arrayfind3; t.drop(); t.save({a: [1, 2]}); diff --git a/jstests/core/query/array/arrayfind4.js b/jstests/core/query/array/arrayfind4.js index 2d7c0e03668..231abee50dd 100644 --- a/jstests/core/query/array/arrayfind4.js +++ b/jstests/core/query/array/arrayfind4.js @@ -4,7 +4,7 @@ // Test query empty array SERVER-2258 -t = db.jstests_arrayfind4; +let t = db.jstests_arrayfind4; t.drop(); t.save({a: []}); diff --git a/jstests/core/query/array/arrayfind5.js b/jstests/core/query/array/arrayfind5.js index 004231e0893..6238284f89a 100644 --- a/jstests/core/query/array/arrayfind5.js +++ b/jstests/core/query/array/arrayfind5.js @@ -4,7 +4,7 @@ // cqf_incompatible, // ] -t = db.jstests_arrayfind5; +let t = db.jstests_arrayfind5; t.drop(); function check(nullElemMatch) { diff --git a/jstests/core/query/array/arrayfind6.js b/jstests/core/query/array/arrayfind6.js index bd91859c9dc..2788fa6d07e 100644 --- a/jstests/core/query/array/arrayfind6.js +++ b/jstests/core/query/array/arrayfind6.js @@ -1,6 +1,6 @@ // Check index bound determination for $not:$elemMatch queries. SERVER-5740 -t = db.jstests_arrayfind6; +let t = db.jstests_arrayfind6; t.drop(); t.save({a: [{b: 1, c: 2}]}); diff --git a/jstests/core/query/array/arrayfind7.js b/jstests/core/query/array/arrayfind7.js index be2061c5c0d..2d3fe471797 100644 --- a/jstests/core/query/array/arrayfind7.js +++ b/jstests/core/query/array/arrayfind7.js @@ -1,6 +1,6 @@ // Nested $elemMatch clauses. SERVER-5741 -t = db.jstests_arrayfind7; +let t = db.jstests_arrayfind7; t.drop(); t.save({a: [{b: [{c: 1, d: 2}]}]}); diff --git a/jstests/core/query/array/arrayfind9.js b/jstests/core/query/array/arrayfind9.js index 5406ae8c1d1..88a781e9999 100644 --- a/jstests/core/query/array/arrayfind9.js +++ b/jstests/core/query/array/arrayfind9.js @@ -1,6 +1,6 @@ // Assorted $elemMatch behavior checks. -t = db.jstests_arrayfind9; +let t = db.jstests_arrayfind9; t.drop(); // Top level field $elemMatch:$not matching @@ -27,8 +27,8 @@ t.drop(); t.save({a: [{b: [0, 2]}]}); t.createIndex({a: 1}); t.createIndex({'a.b': 1}); -plans = [{$natural: 1}, {a: 1}, {'a.b': 1}]; -for (i in plans) { - p = plans[i]; +let plans = [{$natural: 1}, {a: 1}, {'a.b': 1}]; +for (let i in plans) { + let p = plans[i]; assert.eq(1, t.find({a: {$elemMatch: {b: {$gte: 1, $lte: 1}}}}).hint(p).itcount()); } diff --git a/jstests/core/query/array/arrayfinda.js b/jstests/core/query/array/arrayfinda.js index 163af3d8d29..f79c7bf7a37 100644 --- a/jstests/core/query/array/arrayfinda.js +++ b/jstests/core/query/array/arrayfinda.js @@ -1,6 +1,6 @@ // Assorted $elemMatch matching behavior checks. -t = db.jstests_arrayfinda; +let t = db.jstests_arrayfinda; t.drop(); // $elemMatch only matches elements within arrays (a descriptive, not a normative test). diff --git a/jstests/core/query/basic1.js b/jstests/core/query/basic1.js index cc2917fb5a3..6ed22a1422c 100644 --- a/jstests/core/query/basic1.js +++ b/jstests/core/query/basic1.js @@ -1,11 +1,9 @@ // @tags: [does_not_support_stepdowns] -t = db.getCollection("basic1"); +let t = db.getCollection("basic1"); t.drop(); -o = { - a: 1 -}; +let o = {a: 1}; t.save(o); assert.eq(1, t.findOne().a, "first"); diff --git a/jstests/core/query/basic2.js b/jstests/core/query/basic2.js index 3500d9fbdb5..d4501e3474f 100644 --- a/jstests/core/query/basic2.js +++ b/jstests/core/query/basic2.js @@ -3,12 +3,10 @@ // requires_non_retryable_writes, // ] -t = db.getCollection("basic2"); +let t = db.getCollection("basic2"); t.drop(); -o = { - n: 2 -}; +let o = {n: 2}; t.save(o); assert.eq(1, t.find().count()); diff --git a/jstests/core/query/basic4.js b/jstests/core/query/basic4.js index 4b2cf6f96be..e94c5868c80 100644 --- a/jstests/core/query/basic4.js +++ b/jstests/core/query/basic4.js @@ -1,4 +1,4 @@ -t = db.getCollection("basic4"); +let t = db.getCollection("basic4"); t.drop(); t.save({a: 1, b: 1.0}); diff --git a/jstests/core/query/basic5.js b/jstests/core/query/basic5.js index 7ec41ef7872..e1a0df35bbb 100644 --- a/jstests/core/query/basic5.js +++ b/jstests/core/query/basic5.js @@ -1,4 +1,4 @@ -t = db.getCollection("basic5"); +let t = db.getCollection("basic5"); t.drop(); t.save({a: 1, b: [1, 2, 3]}); diff --git a/jstests/core/query/basic6.js b/jstests/core/query/basic6.js index 89aef4acc2e..fb8d85b2f79 100644 --- a/jstests/core/query/basic6.js +++ b/jstests/core/query/basic6.js @@ -4,7 +4,7 @@ * ] */ -t = db.basic6; +let t = db.basic6; t.findOne(); t.a.findOne(); diff --git a/jstests/core/query/basic7.js b/jstests/core/query/basic7.js index dc6f18cc95b..33403380355 100644 --- a/jstests/core/query/basic7.js +++ b/jstests/core/query/basic7.js @@ -1,5 +1,5 @@ -t = db.basic7; +let t = db.basic7; t.drop(); t.save({a: 1}); diff --git a/jstests/core/query/basic8.js b/jstests/core/query/basic8.js index 4a35de6963b..58ab069fa3b 100644 --- a/jstests/core/query/basic8.js +++ b/jstests/core/query/basic8.js @@ -1,10 +1,10 @@ // @tags: [requires_fastcount] -t = db.basic8; +let t = db.basic8; t.drop(); t.save({a: 1}); -o = t.findOne(); +let o = t.findOne(); o.b = 2; t.save(o); diff --git a/jstests/core/query/basica.js b/jstests/core/query/basica.js index 1fe8b7c5de4..569b41ee90d 100644 --- a/jstests/core/query/basica.js +++ b/jstests/core/query/basica.js @@ -1,11 +1,11 @@ -t = db.basica; +let t = db.basica; t.drop(); t.save({a: 1, b: [{x: 2, y: 2}, {x: 3, y: 3}]}); -x = t.findOne(); +let x = t.findOne(); x.b["0"].x = 4; x.b["0"].z = 4; x.b[0].m = 9; diff --git a/jstests/core/query/count/count3.js b/jstests/core/query/count/count3.js index d93df020f0b..51fb5d5d4c8 100644 --- a/jstests/core/query/count/count3.js +++ b/jstests/core/query/count/count3.js @@ -1,5 +1,5 @@ -t = db.count3; +let t = db.count3; t.drop(); diff --git a/jstests/core/query/count/count5.js b/jstests/core/query/count/count5.js index ceedf62b336..81fd8786bfc 100644 --- a/jstests/core/query/count/count5.js +++ b/jstests/core/query/count/count5.js @@ -1,15 +1,13 @@ // @tags: [requires_fastcount] -t = db.count5; +let t = db.count5; t.drop(); -for (i = 0; i < 100; i++) { +for (let i = 0; i < 100; i++) { t.save({x: i}); } -q = { - x: {$gt: 25, $lte: 75} -}; +let q = {x: {$gt: 25, $lte: 75}}; assert.eq(50, t.find(q).count(), "A"); assert.eq(50, t.find(q).itcount(), "B"); diff --git a/jstests/core/query/count/count6.js b/jstests/core/query/count/count6.js index 78735c89c26..8814b2b76a0 100644 --- a/jstests/core/query/count/count6.js +++ b/jstests/core/query/count/count6.js @@ -2,7 +2,7 @@ // // @tags: [requires_fastcount] -t = db.jstests_count6; +let t = db.jstests_count6; function checkCountForObject(obj) { t.drop(); diff --git a/jstests/core/query/count/count7.js b/jstests/core/query/count/count7.js index 443134474a8..cef47b46c2c 100644 --- a/jstests/core/query/count/count7.js +++ b/jstests/core/query/count/count7.js @@ -2,7 +2,7 @@ // Check normal count matching and deduping. -t = db.jstests_count7; +let t = db.jstests_count7; t.drop(); t.createIndex({a: 1}); diff --git a/jstests/core/query/count/count9.js b/jstests/core/query/count/count9.js index 062f099e513..250ada94cb1 100644 --- a/jstests/core/query/count/count9.js +++ b/jstests/core/query/count/count9.js @@ -1,6 +1,6 @@ // Test fast mode count with multikey entries. -t = db.jstests_count9; +let t = db.jstests_count9; t.drop(); t.createIndex({a: 1}); diff --git a/jstests/core/query/count/countb.js b/jstests/core/query/count/countb.js index 869825b25a1..cbce10c7e4e 100644 --- a/jstests/core/query/count/countb.js +++ b/jstests/core/query/count/countb.js @@ -4,7 +4,7 @@ // requires_scripting, // ] -t = db.jstests_countb; +let t = db.jstests_countb; t.drop(); t.createIndex({a: 1}); diff --git a/jstests/core/query/cursor/cursor1.js b/jstests/core/query/cursor/cursor1.js index 1cb00cc82fb..458787bf6d0 100644 --- a/jstests/core/query/cursor/cursor1.js +++ b/jstests/core/query/cursor/cursor1.js @@ -1,13 +1,13 @@ // @tags: [requires_getmore, requires_fastcount] -t = db.cursor1; +let t = db.cursor1; t.drop(); -big = ""; +let big = ""; while (big.length < 50000) big += "asdasdasdasdsdsdadsasdasdasD"; -num = Math.ceil(10000000 / big.length); +let num = Math.ceil(10000000 / big.length); for (var i = 0; i < num; i++) { t.save({num: i, str: big}); diff --git a/jstests/core/query/cursor/cursor3.js b/jstests/core/query/cursor/cursor3.js index 8e5672d4b3b..acf1339c345 100644 --- a/jstests/core/query/cursor/cursor3.js +++ b/jstests/core/query/cursor/cursor3.js @@ -4,19 +4,19 @@ // assumes_read_concern_local, // ] -testNum = 1; +let testNum = 1; function checkResults(expected, cursor, testNum) { assert.eq(expected.length, cursor.count(), "testNum: " + testNum + " A : " + tojson(cursor.toArray()) + " " + tojson(cursor.explain())); - for (i = 0; i < expected.length; ++i) { + for (let i = 0; i < expected.length; ++i) { assert.eq(expected[i], cursor[i]["a"], "testNum: " + testNum + " B"); } } -t = db.cursor3; +let t = db.cursor3; t.drop(); t.save({a: 0}); diff --git a/jstests/core/query/cursor/cursor4.js b/jstests/core/query/cursor/cursor4.js index d0440d329f1..32688ef7c55 100644 --- a/jstests/core/query/cursor/cursor4.js +++ b/jstests/core/query/cursor/cursor4.js @@ -2,21 +2,21 @@ function checkResults(expected, cursor) { assert.eq(expected.length, cursor.count()); - for (i = 0; i < expected.length; ++i) { + for (let i = 0; i < expected.length; ++i) { assert.eq(expected[i].a, cursor[i].a); assert.eq(expected[i].b, cursor[i].b); } } function testConstrainedFindMultiFieldSorting(db) { - r = db.ed_db_cursor4_cfmfs; + let r = db.ed_db_cursor4_cfmfs; r.drop(); - 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) + let entries = [{a: 0, b: 0}, {a: 0, b: 1}, {a: 1, b: 1}, {a: 1, b: 1}, {a: 2, b: 0}]; + for (let i = 0; i < entries.length; ++i) r.save(entries[i]); r.createIndex({a: 1, b: 1}); - reverseEntries = entries.slice(); + let reverseEntries = entries.slice(); reverseEntries.reverse(); checkResults(entries.slice(2, 4), r.find({a: 1, b: 1}).sort({a: 1, b: 1}).hint({a: 1, b: 1})); diff --git a/jstests/core/query/cursor/cursor5.js b/jstests/core/query/cursor/cursor5.js index aab03473255..e3764fdf039 100644 --- a/jstests/core/query/cursor/cursor5.js +++ b/jstests/core/query/cursor/cursor5.js @@ -2,7 +2,7 @@ function checkResults(expected, cursor) { assert.eq(expected.length, cursor.count()); - for (i = 0; i < expected.length; ++i) { + for (let i = 0; i < expected.length; ++i) { assert.eq(expected[i].a.b, cursor[i].a.b); assert.eq(expected[i].a.c, cursor[i].a.c); assert.eq(expected[i].a.d, cursor[i].a.d); @@ -11,10 +11,10 @@ function checkResults(expected, cursor) { } function testBoundsWithSubobjectIndexes(db) { - r = db.ed_db_cursor5_bwsi; + let r = db.ed_db_cursor5_bwsi; r.drop(); - z = [ + let z = [ {a: {b: 1, c: 2, d: 3}, e: 4}, {a: {b: 1, c: 2, d: 3}, e: 5}, {a: {b: 1, c: 2, d: 4}, e: 4}, @@ -22,10 +22,10 @@ function testBoundsWithSubobjectIndexes(db) { {a: {b: 2, c: 2, d: 3}, e: 4}, {a: {b: 2, c: 2, d: 3}, e: 5} ]; - for (i = 0; i < z.length; ++i) + for (let i = 0; i < z.length; ++i) r.save(z[i]); - idx = {"a.d": 1, a: 1, e: -1}; - rIdx = {"a.d": -1, a: -1, e: 1}; + let idx = {"a.d": 1, a: 1, e: -1}; + let rIdx = {"a.d": -1, a: -1, e: 1}; r.createIndex(idx); checkResults([z[0], z[4], z[2]], r.find({e: 4}).sort(idx).hint(idx)); diff --git a/jstests/core/query/cursor/cursor6.js b/jstests/core/query/cursor/cursor6.js index dde1f9069cb..ad55dad6d25 100644 --- a/jstests/core/query/cursor/cursor6.js +++ b/jstests/core/query/cursor/cursor6.js @@ -13,7 +13,7 @@ function check(indexed) { hint = {$natural: 1}; } - f = r.find().sort({a: 1, b: 1}).hint(hint); + let f = r.find().sort({a: 1, b: 1}).hint(hint); eq(z[0], f[0]); eq(z[1], f[1]); eq(z[2], f[2]); @@ -50,11 +50,11 @@ function check(indexed) { eq(z[0], f[3]); } -r = db.ed_db_cursor6; +let r = db.ed_db_cursor6; r.drop(); -z = [{a: 1, b: 1}, {a: 1, b: 2}, {a: 2, b: 1}, {a: 2, b: 2}]; -for (i = 0; i < z.length; ++i) +let z = [{a: 1, b: 1}, {a: 1, b: 2}, {a: 2, b: 1}, {a: 2, b: 2}]; +for (let i = 0; i < z.length; ++i) r.save(z[i]); r.createIndex({a: 1, b: -1}); diff --git a/jstests/core/query/cursor/cursor7.js b/jstests/core/query/cursor/cursor7.js index 4a21c420274..9e75ff605ff 100644 --- a/jstests/core/query/cursor/cursor7.js +++ b/jstests/core/query/cursor/cursor7.js @@ -2,21 +2,21 @@ function checkResults(expected, cursor) { assert.eq(expected.length, cursor.count()); - for (i = 0; i < expected.length; ++i) { + for (let i = 0; i < expected.length; ++i) { assert.eq(expected[i].a, cursor[i].a); assert.eq(expected[i].b, cursor[i].b); } } function testMultipleInequalities(db) { - r = db.ed_db_cursor_mi; + let r = db.ed_db_cursor_mi; r.drop(); - z = [{a: 1, b: 2}, {a: 3, b: 4}, {a: 5, b: 6}, {a: 7, b: 8}]; - for (i = 0; i < z.length; ++i) + let z = [{a: 1, b: 2}, {a: 3, b: 4}, {a: 5, b: 6}, {a: 7, b: 8}]; + for (let i = 0; i < z.length; ++i) r.save(z[i]); - idx = {a: 1, b: 1}; - rIdx = {a: -1, b: -1}; + let idx = {a: 1, b: 1}; + let rIdx = {a: -1, b: -1}; r.createIndex(idx); checkResults([z[2], z[3]], r.find({a: {$gt: 3}}).sort(idx).hint(idx)); diff --git a/jstests/core/query/cursor/tailable_cursor_invalidation.js b/jstests/core/query/cursor/tailable_cursor_invalidation.js index d59e852d63d..1cd82554ef5 100644 --- a/jstests/core/query/cursor/tailable_cursor_invalidation.js +++ b/jstests/core/query/cursor/tailable_cursor_invalidation.js @@ -6,6 +6,7 @@ // # This test has statements that do not support non-local read concern. // does_not_support_causal_consistency, // ] +load("jstests/libs/fixture_helpers.js"); // Tests for the behavior of tailable cursors when a collection is dropped or the cursor is // otherwise invalidated. @@ -26,8 +27,7 @@ const emptyBatchCursorId = assert .commandWorked(db.runCommand( {find: collName, tailable: true, awaitData: true, batchSize: 0})) .cursor.id; -const isMongos = db.adminCommand({isdbgrid: 1}).isdbgrid; -if (isMongos) { +if (FixtureHelpers.isMongos(db)) { // Mongos will let you establish a cursor with batch size 0 and return to you before it // realizes the shard's cursor is exhausted. The next getMore should return a 0 cursor id // though. diff --git a/jstests/core/query/date/date1.js b/jstests/core/query/date/date1.js index 65449c662b5..f5e608bbaeb 100644 --- a/jstests/core/query/date/date1.js +++ b/jstests/core/query/date/date1.js @@ -1,5 +1,5 @@ -t = db.date1; +let t = db.date1; function go(d, msg) { t.drop(); diff --git a/jstests/core/query/date/date2.js b/jstests/core/query/date/date2.js index a398058d771..b1d8c3d8b2f 100644 --- a/jstests/core/query/date/date2.js +++ b/jstests/core/query/date/date2.js @@ -1,6 +1,6 @@ // Check that it's possible to compare a Date to a Timestamp, but they are never equal - SERVER-3304 -t = db.jstests_date2; +let t = db.jstests_date2; t.drop(); t.createIndex({a: 1}); diff --git a/jstests/core/query/date/date3.js b/jstests/core/query/date/date3.js index e3eaea620ec..06f8af3fce7 100644 --- a/jstests/core/query/date/date3.js +++ b/jstests/core/query/date/date3.js @@ -2,12 +2,12 @@ // // @tags: [requires_fastcount] -t = db.date3; +let t = db.date3; t.drop(); -d1 = new Date(-1000); -dz = new Date(0); -d2 = new Date(1000); +let d1 = new Date(-1000); +let dz = new Date(0); +let d2 = new Date(1000); t.save({x: 3, d: dz}); t.save({x: 2, d: d2}); diff --git a/jstests/core/query/dbref/dbref1.js b/jstests/core/query/dbref/dbref1.js index b5bb06f230d..da88f8d5525 100644 --- a/jstests/core/query/dbref/dbref1.js +++ b/jstests/core/query/dbref/dbref1.js @@ -1,6 +1,6 @@ -a = db.dbref1a; -b = db.dbref1b; +let a = db.dbref1a; +let b = db.dbref1b; a.drop(); b.drop(); diff --git a/jstests/core/query/dbref/dbref2.js b/jstests/core/query/dbref/dbref2.js index be0deefeb2d..4efddccbbac 100644 --- a/jstests/core/query/dbref/dbref2.js +++ b/jstests/core/query/dbref/dbref2.js @@ -1,6 +1,6 @@ -a = db.dbref2a; -b = db.dbref2b; -c = db.dbref2c; +let a = db.dbref2a; +let b = db.dbref2b; +let c = db.dbref2c; a.drop(); b.drop(); diff --git a/jstests/core/query/dbref/ref.js b/jstests/core/query/dbref/ref.js index 0d1160482fc..696b44c7d91 100644 --- a/jstests/core/query/dbref/ref.js +++ b/jstests/core/query/dbref/ref.js @@ -10,7 +10,7 @@ assert.throws(function() { }); db.things.save({name: "abc"}); -x = db.things.findOne(); +let x = db.things.findOne(); x.o = new DBPointer("otherthings", other._id); db.things.save(x); diff --git a/jstests/core/query/dbref/ref2.js b/jstests/core/query/dbref/ref2.js index 6b284b1f59f..a17b084e8b1 100644 --- a/jstests/core/query/dbref/ref2.js +++ b/jstests/core/query/dbref/ref2.js @@ -1,16 +1,10 @@ // @tags: [requires_fastcount] -t = db.ref2; +let t = db.ref2; t.drop(); -a = { - $ref: "foo", - $id: 1 -}; -b = { - $ref: "foo", - $id: 2 -}; +let a = {$ref: "foo", $id: 1}; +let b = {$ref: "foo", $id: 2}; t.save({name: "a", r: a}); t.save({name: "b", r: b}); diff --git a/jstests/core/query/dbref/ref3.js b/jstests/core/query/dbref/ref3.js index 4406863d899..f73c7d0fad4 100644 --- a/jstests/core/query/dbref/ref3.js +++ b/jstests/core/query/dbref/ref3.js @@ -8,7 +8,7 @@ var other = {s: "other thing", n: 1}; db.otherthings3.save(other); db.things3.save({name: "abc"}); -x = db.things3.findOne(); +let x = db.things3.findOne(); x.o = new DBRef("otherthings3", other._id); db.things3.save(x); diff --git a/jstests/core/query/dbref/ref4.js b/jstests/core/query/dbref/ref4.js index 882253f3883..45519b8cac1 100644 --- a/jstests/core/query/dbref/ref4.js +++ b/jstests/core/query/dbref/ref4.js @@ -1,6 +1,6 @@ -a = db.ref4a; -b = db.ref4b; +let a = db.ref4a; +let b = db.ref4b; a.drop(); b.drop(); @@ -11,7 +11,7 @@ b.save(other); a.save({name: "abc", others: [new DBRef("ref4b", other._id), new DBPointer("ref4b", other._id)]}); assert(a.findOne().others[0].fetch().n == 17, "dbref broken 1"); -x = Array.fetchRefs(a.findOne().others); +let x = Array.fetchRefs(a.findOne().others); assert.eq(2, x.length, "A"); assert.eq(17, x[0].n, "B"); assert.eq(17, x[1].n, "C"); diff --git a/jstests/core/query/distinct/distinct2.js b/jstests/core/query/distinct/distinct2.js index fc6ff7779b7..9b886e56b43 100644 --- a/jstests/core/query/distinct/distinct2.js +++ b/jstests/core/query/distinct/distinct2.js @@ -1,5 +1,5 @@ -t = db.distinct2; +let t = db.distinct2; t.drop(); t.save({a: null}); diff --git a/jstests/core/query/distinct/distinct3.js b/jstests/core/query/distinct/distinct3.js index c2aaaad79e5..eb3a0077d9c 100644 --- a/jstests/core/query/distinct/distinct3.js +++ b/jstests/core/query/distinct/distinct3.js @@ -6,35 +6,35 @@ // Yield and delete test case for query optimizer cursor. SERVER-4401 -t = db.jstests_distinct3; +let t = db.jstests_distinct3; t.drop(); t.createIndex({a: 1}); t.createIndex({b: 1}); var bulk = t.initializeUnorderedBulkOp(); -for (i = 0; i < 50; ++i) { - for (j = 0; j < 2; ++j) { +for (let i = 0; i < 50; ++i) { + for (let j = 0; j < 2; ++j) { bulk.insert({a: i, c: i, d: j}); } } -for (i = 0; i < 100; ++i) { +for (let i = 0; i < 100; ++i) { bulk.insert({b: i, c: i + 50}); } assert.commandWorked(bulk.execute()); // Attempt to remove the last match for the {a:1} index scan while distinct is yielding. -p = startParallelShell('for( i = 0; i < 100; ++i ) { ' + - ' var bulk = db.jstests_distinct3.initializeUnorderedBulkOp();' + - ' bulk.find( { a:49 } ).remove(); ' + - ' for( j = 0; j < 20; ++j ) { ' + - ' bulk.insert( { a:49, c:49, d:j } ); ' + - ' } ' + - ' assert.commandWorked(bulk.execute()); ' + - '} '); +let p = startParallelShell('for( i = 0; i < 100; ++i ) { ' + + ' var bulk = db.jstests_distinct3.initializeUnorderedBulkOp();' + + ' bulk.find( { a:49 } ).remove(); ' + + ' for( j = 0; j < 20; ++j ) { ' + + ' bulk.insert( { a:49, c:49, d:j } ); ' + + ' } ' + + ' assert.commandWorked(bulk.execute()); ' + + '} '); -for (i = 0; i < 100; ++i) { - count = t.distinct('c', {$or: [{a: {$gte: 0}, d: 0}, {b: {$gte: 0}}]}).length; +for (let i = 0; i < 100; ++i) { + let count = t.distinct('c', {$or: [{a: {$gte: 0}, d: 0}, {b: {$gte: 0}}]}).length; assert.gt(count, 100); } diff --git a/jstests/core/query/distinct/distinct_array1.js b/jstests/core/query/distinct/distinct_array1.js index cb82c25bbff..a812c1c23f0 100644 --- a/jstests/core/query/distinct/distinct_array1.js +++ b/jstests/core/query/distinct/distinct_array1.js @@ -1,4 +1,4 @@ -t = db.distinct_array1; +let t = db.distinct_array1; t.drop(); t.save({a: [1, 2, 3]}); @@ -7,7 +7,7 @@ t.save({a: [3, 4, 5]}); t.save({a: 9}); // Without index. -res = t.distinct("a").sort(); +let res = t.distinct("a").sort(); assert.eq("1,2,3,4,5,9", res.toString()); // Array element 0 without index. diff --git a/jstests/core/query/exists/exists.js b/jstests/core/query/exists/exists.js index b85d80c36a7..f29320b002e 100644 --- a/jstests/core/query/exists/exists.js +++ b/jstests/core/query/exists/exists.js @@ -2,7 +2,7 @@ // requires_fastcount, // ] -t = db.jstests_exists; +let t = db.jstests_exists; t.drop(); t.save({}); diff --git a/jstests/core/query/exists/exists2.js b/jstests/core/query/exists/exists2.js index 0764d859c3b..6d175584eec 100644 --- a/jstests/core/query/exists/exists2.js +++ b/jstests/core/query/exists/exists2.js @@ -1,4 +1,4 @@ -t = db.exists2; +let t = db.exists2; t.drop(); t.save({a: 1, b: 1}); diff --git a/jstests/core/query/exists/exists3.js b/jstests/core/query/exists/exists3.js index 510d63c3752..1b5939f07ce 100644 --- a/jstests/core/query/exists/exists3.js +++ b/jstests/core/query/exists/exists3.js @@ -1,6 +1,6 @@ // Check exists with non empty document, based on SERVER-2470 example. -t = db.jstests_exists3; +let t = db.jstests_exists3; t.drop(); t.insert({a: 1, b: 2}); diff --git a/jstests/core/query/exists/exists4.js b/jstests/core/query/exists/exists4.js index a533ca53e9c..4960fe32ff7 100644 --- a/jstests/core/query/exists/exists4.js +++ b/jstests/core/query/exists/exists4.js @@ -1,6 +1,6 @@ // Check various exists cases, based on SERVER-1735 example. -t = db.jstests_exists4; +let t = db.jstests_exists4; t.drop(); t.createIndex({date: -1, country_code: 1, user_id: 1}, {unique: 1, background: 1}); diff --git a/jstests/core/query/exists/exists5.js b/jstests/core/query/exists/exists5.js index 2f4b1a9b8de..112e8243b99 100644 --- a/jstests/core/query/exists/exists5.js +++ b/jstests/core/query/exists/exists5.js @@ -1,6 +1,6 @@ // Test some $not/$exists cases. -t = db.jstests_exists5; +let t = db.jstests_exists5; t.drop(); t.save({a: 1}); diff --git a/jstests/core/query/exists/exists6.js b/jstests/core/query/exists/exists6.js index 736574db895..71fd20d3c26 100644 --- a/jstests/core/query/exists/exists6.js +++ b/jstests/core/query/exists/exists6.js @@ -1,6 +1,6 @@ // SERVER-393 Test indexed matching with $exists. -t = db.jstests_exists6; +let t = db.jstests_exists6; t.drop(); t.createIndex({b: 1}); diff --git a/jstests/core/query/exists/exists7.js b/jstests/core/query/exists/exists7.js index 285559e82f8..1f25db5fedf 100644 --- a/jstests/core/query/exists/exists7.js +++ b/jstests/core/query/exists/exists7.js @@ -2,7 +2,7 @@ // Test that non boolean value types are allowed with $exists spec. SERVER-2322 -t = db.jstests_exists7; +let t = db.jstests_exists7; t.drop(); function testIntegerExistsSpec() { diff --git a/jstests/core/query/exists/exists8.js b/jstests/core/query/exists/exists8.js index f22a3be44f4..3c506cd5781 100644 --- a/jstests/core/query/exists/exists8.js +++ b/jstests/core/query/exists/exists8.js @@ -2,7 +2,7 @@ // Test $exists with array element field names SERVER-2897 -t = db.jstests_exists8; +let t = db.jstests_exists8; t.drop(); t.save({a: [1]}); diff --git a/jstests/core/query/exists/exists9.js b/jstests/core/query/exists/exists9.js index c187bb3a101..d822ae95f0a 100644 --- a/jstests/core/query/exists/exists9.js +++ b/jstests/core/query/exists/exists9.js @@ -1,6 +1,6 @@ // SERVER-393 Test exists with various empty array and empty object cases. -t = db.jstests_exists9; +let t = db.jstests_exists9; t.drop(); // Check existence of missing nested field. diff --git a/jstests/core/query/exists/existsb.js b/jstests/core/query/exists/existsb.js index 64ee3cf9a88..b327311a4ef 100644 --- a/jstests/core/query/exists/existsb.js +++ b/jstests/core/query/exists/existsb.js @@ -20,7 +20,7 @@ // everything but {} will have an index entry. // Let's make sure we handle this properly! -t = db.jstests_existsb; +let t = db.jstests_existsb; t.drop(); t.save({}); diff --git a/jstests/core/query/explain/explain1.js b/jstests/core/query/explain/explain1.js index 2de3e2f89d2..cdbd8751dda 100644 --- a/jstests/core/query/explain/explain1.js +++ b/jstests/core/query/explain/explain1.js @@ -2,16 +2,14 @@ // assumes_read_concern_local, // ] -t = db.explain1; +let t = db.explain1; t.drop(); for (var i = 0; i < 100; i++) { t.save({x: i}); } -q = { - x: {$gt: 50} -}; +let q = {x: {$gt: 50}}; assert.eq(49, t.find(q).count(), "A"); assert.eq(49, t.find(q).itcount(), "B"); diff --git a/jstests/core/query/explain/explain4.js b/jstests/core/query/explain/explain4.js index e49b188cb65..f3e2b460c5e 100644 --- a/jstests/core/query/explain/explain4.js +++ b/jstests/core/query/explain/explain4.js @@ -3,16 +3,16 @@ // assumes_read_concern_local, // ] -t = db.jstests_explain4; +let t = db.jstests_explain4; t.drop(); t.createIndex({a: 1}); -for (i = 0; i < 10; ++i) { +for (let i = 0; i < 10; ++i) { t.save({a: i, b: 0}); } -explain = t.find({a: {$gte: 0}, b: 0}).sort({a: 1}).hint({a: 1}).limit(5).explain(true); +let explain = t.find({a: {$gte: 0}, b: 0}).sort({a: 1}).hint({a: 1}).limit(5).explain(true); // Five results are expected, matching the limit spec. assert.eq(5, explain.executionStats.nReturned); diff --git a/jstests/core/query/explain/explain6.js b/jstests/core/query/explain/explain6.js index fbb6ecf6d76..73bfced5116 100644 --- a/jstests/core/query/explain/explain6.js +++ b/jstests/core/query/explain/explain6.js @@ -6,7 +6,7 @@ // Basic test which checks the number of documents returned, keys examined, and documents // examined as reported by explain. -t = db.jstests_explain6; +let t = db.jstests_explain6; t.drop(); t.createIndex({a: 1, b: 1}); @@ -15,7 +15,7 @@ t.createIndex({b: 1, a: 1}); t.save({a: 0, b: 1}); t.save({a: 1, b: 0}); -explain = t.find({a: {$gte: 0}, b: {$gte: 0}}).explain(true); +let explain = t.find({a: {$gte: 0}, b: {$gte: 0}}).explain(true); assert.eq(2, explain.executionStats.nReturned); assert.eq(2, explain.executionStats.totalKeysExamined); diff --git a/jstests/core/query/explain/explain_batch_size.js b/jstests/core/query/explain/explain_batch_size.js index d31b54b3f16..aec1124f171 100644 --- a/jstests/core/query/explain/explain_batch_size.js +++ b/jstests/core/query/explain/explain_batch_size.js @@ -8,11 +8,11 @@ // requires_fastcount, // ] -t = db.explain_batch_size; +let t = db.explain_batch_size; t.drop(); var n = 3; -for (i = 0; i < n; i++) { +for (let i = 0; i < n; i++) { t.save({x: i}); } diff --git a/jstests/core/query/expr/expr.js b/jstests/core/query/expr/expr.js index 737cab39f15..81ebf13a8d3 100644 --- a/jstests/core/query/expr/expr.js +++ b/jstests/core/query/expr/expr.js @@ -15,13 +15,10 @@ "use strict"; load("jstests/libs/sbe_assert_error_override.js"); // For 'assert.errorCodeEq'. +load("jstests/libs/fixture_helpers.js"); const coll = db.expr; -const hello = db.runCommand("hello"); -assert.commandWorked(hello); -const isMongos = (hello.msg === "isdbgrid"); - // // $expr in aggregate. // @@ -126,7 +123,7 @@ assert.throws(function() { // 'executionSuccess' field. let explain = coll.find({$expr: {$divide: [1, "$a"]}}).explain("executionStats"); // Accommodate format differences between explain via mongos and explain directly on a mongod. -if (!isMongos) { +if (!FixtureHelpers.isMongos(db)) { assert(explain.hasOwnProperty("executionStats"), explain); assert.eq(explain.executionStats.executionSuccess, false, explain); assert.errorCodeEq(explain.executionStats.errorCode, [16609, ErrorCodes.TypeMismatch], explain); diff --git a/jstests/core/query/find/find2.js b/jstests/core/query/find/find2.js index a793c60b804..747775bd4b0 100644 --- a/jstests/core/query/find/find2.js +++ b/jstests/core/query/find/find2.js @@ -3,13 +3,13 @@ // @tags: [requires_fastcount] function testObjectIdFind(db) { - r = db.ed_db_find2_oif; + let r = db.ed_db_find2_oif; r.drop(); - for (i = 0; i < 3; ++i) + for (let i = 0; i < 3; ++i) r.save({}); - f = r.find().sort({_id: 1}); + let f = r.find().sort({_id: 1}); assert.eq(3, f.count()); assert(f[0]._id < f[1]._id); assert(f[1]._id < f[2]._id); diff --git a/jstests/core/query/find/find6.js b/jstests/core/query/find/find6.js index d76cc1d5fb5..4b90cfe8cf7 100644 --- a/jstests/core/query/find/find6.js +++ b/jstests/core/query/find/find6.js @@ -4,7 +4,7 @@ // requires_scripting, // ] -t = db.find6; +let t = db.find6; t.drop(); t.save({a: 1}); @@ -16,7 +16,7 @@ assert.eq(1, t.find("function() { return this.b == null; }").itcount(), "C"); assert.eq(1, t.find("function() { return this.b == null; }").count(), "D"); /* test some stuff with dot array notation */ -q = db.find6a; +let q = db.find6a; q.drop(); q.insert({"a": [{"0": 1}]}); q.insert({"a": [{"0": 2}]}); diff --git a/jstests/core/query/find/find7.js b/jstests/core/query/find/find7.js index ed18dcbb0ff..56fbd859299 100644 --- a/jstests/core/query/find/find7.js +++ b/jstests/core/query/find/find7.js @@ -1,10 +1,7 @@ -t = db.find7; +let t = db.find7; t.drop(); -x = { - "_id": {"d": 3649, "w": "signed"}, - "u": {"3649": 5} -}; +let x = {"_id": {"d": 3649, "w": "signed"}, "u": {"3649": 5}}; t.insert(x); assert.eq(x, t.findOne(), "A1"); assert.eq(x, t.findOne({_id: x._id}), "A2"); diff --git a/jstests/core/query/find/find8.js b/jstests/core/query/find/find8.js index 14930a056e7..a64f89496f5 100644 --- a/jstests/core/query/find/find8.js +++ b/jstests/core/query/find/find8.js @@ -1,6 +1,6 @@ // SERVER-1932 Test unindexed matching of a range that is only valid in a multikey context. -t = db.jstests_find8; +let t = db.jstests_find8; t.drop(); t.save({a: [1, 10]}); diff --git a/jstests/core/query/find/find9.js b/jstests/core/query/find/find9.js index be6bfdb2ccf..e4858e09490 100644 --- a/jstests/core/query/find/find9.js +++ b/jstests/core/query/find/find9.js @@ -2,11 +2,11 @@ // Test that the MaxBytesToReturnToClientAtOnce limit is enforced. -t = db.jstests_find9; +let t = db.jstests_find9; t.drop(); -big = new Array(500000).toString(); -for (i = 0; i < 60; ++i) { +let big = new Array(500000).toString(); +for (let i = 0; i < 60; ++i) { t.save({a: i, b: big}); } @@ -18,12 +18,12 @@ assert.gt(60, t.find().objsLeftInBatch()); assert.eq(60, t.find({}, {a: 1}).batchSize(80).objsLeftInBatch()); assert.gt(60, t.find().batchSize(80).objsLeftInBatch()); -for (i = 0; i < 60; ++i) { +for (let i = 0; i < 60; ++i) { t.save({a: i, b: big}); } // Check size limit with get more. -c = t.find().batchSize(80); +let c = t.find().batchSize(80); while (c.hasNext()) { assert.gt(60, c.objsLeftInBatch()); c.next(); diff --git a/jstests/core/query/find/finda.js b/jstests/core/query/find/finda.js index 2e1a93cbad8..2a3799f72bf 100644 --- a/jstests/core/query/find/finda.js +++ b/jstests/core/query/find/finda.js @@ -4,10 +4,10 @@ // Tests where the QueryOptimizerCursor enters takeover mode during a query rather than a get more. -t = db.jstests_finda; +let t = db.jstests_finda; t.drop(); -numDocs = 200; +let numDocs = 200; function clearQueryPlanCache() { t.createIndex({c: 1}); @@ -16,12 +16,12 @@ function clearQueryPlanCache() { function assertAllFound(matches) { // printjson( matches ); - found = new Array(numDocs); + let found = new Array(numDocs); for (var i = 0; i < numDocs; ++i) { found[i] = false; } for (var i in matches) { - m = matches[i]; + let m = matches[i]; found[m._id] = true; } for (var i = 0; i < numDocs; ++i) { @@ -34,7 +34,7 @@ function makeCursor(query, projection, sort, batchSize, returnKey) { printjson(query); print("proj:"); printjson(projection); - cursor = t.find(query, projection); + let cursor = t.find(query, projection); if (sort) { cursor.sort(sort); print("sort:"); @@ -53,7 +53,7 @@ function makeCursor(query, projection, sort, batchSize, returnKey) { function checkCursorWithBatchSizeProjection( query, projection, sort, batchSize, expectedLeftInBatch) { clearQueryPlanCache(); - cursor = makeCursor(query, projection, sort, batchSize); + let cursor = makeCursor(query, projection, sort, batchSize); if (TestData.batchSize && batchSize == null) { expectedLeftInBatch = Math.min(TestData.batchSize, expectedLeftInBatch); } @@ -71,10 +71,10 @@ function checkCursorWithBatchSize(query, sort, batchSize, expectedLeftInBatch) { // from the a,_id index. clearQueryPlanCache(); if (expectedLeftInBatch > 110) { - cursor = makeCursor(query, {}, sort, batchSize, true); - lastNonAIndexResult = -1; + let cursor = makeCursor(query, {}, sort, batchSize, true); + let lastNonAIndexResult = -1; for (var i = 0; i < expectedLeftInBatch; ++i) { - next = cursor.next(); + let next = cursor.next(); // Identify the query plan used by checking the fields of a returnKey query. if (!friendlyEqual(['a', '_id'], Object.keySet(next))) { lastNonAIndexResult = i; diff --git a/jstests/core/query/in/in.js b/jstests/core/query/in/in.js index ca8cd77b189..f2a3ab6fcff 100644 --- a/jstests/core/query/in/in.js +++ b/jstests/core/query/in/in.js @@ -1,5 +1,5 @@ -t = db.in1; +let t = db.in1; t.drop(); t.save({a: 1}); diff --git a/jstests/core/query/in/in2.js b/jstests/core/query/in/in2.js index 6682bbc79c1..48f94f6aed6 100644 --- a/jstests/core/query/in/in2.js +++ b/jstests/core/query/in/in2.js @@ -1,5 +1,5 @@ -t = db.in2; +let t = db.in2; function go(name, index) { t.drop(); diff --git a/jstests/core/query/in/in3.js b/jstests/core/query/in/in3.js index bd64329ded4..5bc2b353b45 100644 --- a/jstests/core/query/in/in3.js +++ b/jstests/core/query/in/in3.js @@ -1,6 +1,6 @@ // SERVER-2829 Test arrays matching themselves within a $in expression. -t = db.jstests_in8; +let t = db.jstests_in8; t.drop(); t.save({key: [1]}); diff --git a/jstests/core/query/in/in4.js b/jstests/core/query/in/in4.js index e916ca7c82d..8d18a8b4287 100644 --- a/jstests/core/query/in/in4.js +++ b/jstests/core/query/in/in4.js @@ -2,7 +2,7 @@ // SERVER-2343 Test $in empty array matching. -t = db.jstests_in9; +let t = db.jstests_in9; t.drop(); function someData() { diff --git a/jstests/core/query/in/in5.js b/jstests/core/query/in/in5.js index 80f37e6b473..5a8e63d1888 100644 --- a/jstests/core/query/in/in5.js +++ b/jstests/core/query/in/in5.js @@ -4,28 +4,28 @@ // assumes_no_implicit_index_creation, // ] -t = db.in5; +let t = db.in5; function go(fn) { t.drop(); - o = {}; + let o = {}; o[fn] = {a: 1, b: 2}; t.insert(o); - x = {}; + let x = {}; x[fn] = {a: 1, b: 2}; assert.eq(1, t.find(x).itcount(), "A1 - " + fn); - y = {}; + let y = {}; y[fn] = {$in: [{a: 1, b: 2}]}; assert.eq(1, t.find(y).itcount(), "A2 - " + fn); - z = {}; + let z = {}; z[fn + ".a"] = 1; z[fn + ".b"] = {$in: [2]}; assert.eq(1, t.find(z).itcount(), "A3 - " + fn); // SERVER-1366 - i = {}; + let i = {}; i[fn] = 1; t.createIndex(i); diff --git a/jstests/core/query/in/in6.js b/jstests/core/query/in/in6.js index ab8322cfe0a..8584e1ee954 100644 --- a/jstests/core/query/in/in6.js +++ b/jstests/core/query/in/in6.js @@ -1,4 +1,4 @@ -t = db.jstests_in6; +let t = db.jstests_in6; t.drop(); t.save({}); diff --git a/jstests/core/query/in/in7.js b/jstests/core/query/in/in7.js index 78caf6a85f1..ee2de08c0f4 100644 --- a/jstests/core/query/in/in7.js +++ b/jstests/core/query/in/in7.js @@ -1,6 +1,6 @@ // Uassert when $elemMatch is attempted within $in SERVER-3545 -t = db.jstests_ina; +let t = db.jstests_ina; t.drop(); t.save({}); diff --git a/jstests/core/query/in/in8.js b/jstests/core/query/in/in8.js index f1b6188347c..42a99407ce0 100644 --- a/jstests/core/query/in/in8.js +++ b/jstests/core/query/in/in8.js @@ -1,6 +1,6 @@ // Test $in regular expressions with overlapping index bounds. SERVER-4677 -t = db.jstests_inb; +let t = db.jstests_inb; t.drop(); function checkResults(query) { diff --git a/jstests/core/query/inc/inc1.js b/jstests/core/query/inc/inc1.js index 551d15e0f63..2470b146d70 100644 --- a/jstests/core/query/inc/inc1.js +++ b/jstests/core/query/inc/inc1.js @@ -1,6 +1,6 @@ // @tags: [requires_fastcount] -t = db.inc1; +let t = db.inc1; t.drop(); function test(num, name) { diff --git a/jstests/core/query/inc/inc2.js b/jstests/core/query/inc/inc2.js index debdfde82cb..1d253723b28 100644 --- a/jstests/core/query/inc/inc2.js +++ b/jstests/core/query/inc/inc2.js @@ -1,5 +1,5 @@ -t = db.inc2; +let t = db.inc2; t.drop(); t.save({_id: 1, x: 1}); diff --git a/jstests/core/query/inc/inc3.js b/jstests/core/query/inc/inc3.js index e24165876c6..51a9c9c1587 100644 --- a/jstests/core/query/inc/inc3.js +++ b/jstests/core/query/inc/inc3.js @@ -3,7 +3,7 @@ // key. // @tags: [assumes_unsharded_collection] -t = db.inc3; +let t = db.inc3; t.drop(); t.save({_id: 1, z: 1, a: 1}); diff --git a/jstests/core/query/js/js1.js b/jstests/core/query/js/js1.js index f569606ba54..0a9254c0154 100644 --- a/jstests/core/query/js/js1.js +++ b/jstests/core/query/js/js1.js @@ -4,7 +4,7 @@ // requires_scripting, // ] -t = db.jstests_js1; +let t = db.jstests_js1; t.remove({}); t.save({z: 1}); diff --git a/jstests/core/query/js/js2.js b/jstests/core/query/js/js2.js index a278a520a88..05daee83940 100644 --- a/jstests/core/query/js/js2.js +++ b/jstests/core/query/js/js2.js @@ -2,10 +2,10 @@ // requires_non_retryable_writes //] -t = db.jstests_js2; +let t = db.jstests_js2; t.remove({}); -t2 = db.jstests_js2_2; +let t2 = db.jstests_js2_2; t2.remove({}); assert.eq(0, t2.find().length(), "A"); diff --git a/jstests/core/query/js/js3.js b/jstests/core/query/js/js3.js index c9239bb4176..cb2b03e7787 100644 --- a/jstests/core/query/js/js3.js +++ b/jstests/core/query/js/js3.js @@ -7,13 +7,13 @@ // requires_scripting, // ] -t = db.jstests_js3; +let t = db.jstests_js3; -debug = function(s) { +let debug = function(s) { // printjson( s ); }; -for (z = 0; z < 2; z++) { +for (let z = 0; z < 2; z++) { debug(z); t.drop(); @@ -23,7 +23,7 @@ for (z = 0; z < 2; z++) { t.createIndex({i: 1}); } - for (i = 0; i < 1000; i++) + for (let i = 0; i < 1000; i++) t.save({ i: i, z: "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" @@ -57,17 +57,17 @@ for (z = 0; z < 2; z++) { debug("before indexed find"); - arr = t.find({ - $where: function() { - return obj.i == 7 || obj.i == 8; - } - }).toArray(); + let arr = t.find({ + $where: function() { + return obj.i == 7 || obj.i == 8; + } + }).toArray(); debug(arr); assert.eq(2, arr.length); debug("after indexed find"); - for (i = 1000; i < 2000; i++) + for (let i = 1000; i < 2000; i++) t.save({ i: i, z: "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" diff --git a/jstests/core/query/js/js4.js b/jstests/core/query/js/js4.js index a8beab4a8f6..11e67b2cd2c 100644 --- a/jstests/core/query/js/js4.js +++ b/jstests/core/query/js/js4.js @@ -3,17 +3,10 @@ // requires_scripting, // ] -t = db.jstests_js4; +let t = db.jstests_js4; t.drop(); -real = { - a: 1, - b: "abc", - c: /abc/i, - d: new Date(111911100111), - e: null, - f: true -}; +let real = {a: 1, b: "abc", c: /abc/i, d: new Date(111911100111), e: null, f: true}; t.save(real); diff --git a/jstests/core/query/js/js5.js b/jstests/core/query/js/js5.js index 05071a2b6a6..f41a4de78d4 100644 --- a/jstests/core/query/js/js5.js +++ b/jstests/core/query/js/js5.js @@ -3,7 +3,7 @@ // requires_scripting // ] -t = db.jstests_js5; +let t = db.jstests_js5; t.drop(); t.save({a: 1}); diff --git a/jstests/core/query/js/js8.js b/jstests/core/query/js/js8.js index 4bdf942e2c6..19544649236 100644 --- a/jstests/core/query/js/js8.js +++ b/jstests/core/query/js/js8.js @@ -3,7 +3,7 @@ // requires_scripting, // ] -t = db.jstests_js8; +let t = db.jstests_js8; t.drop(); t.save({a: 1, b: [2, 3, 4]}); diff --git a/jstests/core/query/mr/mr_bigobject.js b/jstests/core/query/mr/mr_bigobject.js index 83089935f35..57d8283af23 100644 --- a/jstests/core/query/mr/mr_bigobject.js +++ b/jstests/core/query/mr/mr_bigobject.js @@ -37,7 +37,7 @@ assert.eq([{_id: 1, value: 1}], outputColl.find().toArray()); // The reduce function processes the expected amount of data. reduceFn = function(k, v) { - total = 0; + let total = 0; for (let i = 0; i < v.length; i++) { const x = v[i]; if (typeof (x) == "number") diff --git a/jstests/core/query/mr/mr_reduce_merge_other_db.js b/jstests/core/query/mr/mr_reduce_merge_other_db.js index 5c730ada182..78559f6788e 100644 --- a/jstests/core/query/mr/mr_reduce_merge_other_db.js +++ b/jstests/core/query/mr/mr_reduce_merge_other_db.js @@ -23,7 +23,7 @@ const outDb = db.getMongo().getDB(outDbStr); const outColl = outDb[outCollStr]; const mapFn = function() { - for (i = 0; i < this.a.length; i++) + for (let i = 0; i < this.a.length; i++) emit(this.a[i], 1); }; const reduceFn = function(k, vs) { diff --git a/jstests/core/query/mr/mr_replace_into_other_db.js b/jstests/core/query/mr/mr_replace_into_other_db.js index 010b9d114af..a807b01f968 100644 --- a/jstests/core/query/mr/mr_replace_into_other_db.js +++ b/jstests/core/query/mr/mr_replace_into_other_db.js @@ -25,7 +25,7 @@ assert.commandWorked(outDb.random_coll.insert({val: 1})); const outColl = outDb[outCollStr]; const mapFn = function() { - for (i = 0; i < this.a.length; i++) + for (let i = 0; i < this.a.length; i++) emit(this.a[i], 1); }; const reduceFn = function(k, vs) { diff --git a/jstests/core/query/mr/mr_sort.js b/jstests/core/query/mr/mr_sort.js index 11ced9f2722..b01eb832e71 100644 --- a/jstests/core/query/mr/mr_sort.js +++ b/jstests/core/query/mr/mr_sort.js @@ -11,7 +11,7 @@ // requires_scripting, // ] -t = db.mr_sort; +let t = db.mr_sort; t.drop(); t.createIndex({x: 1}); @@ -27,15 +27,15 @@ t.insert({x: 7}); t.insert({x: 5}); t.insert({x: 6}); -m = function() { +let m = function() { emit("a", this.x); }; -r = function(k, v) { +let r = function(k, v) { return Array.sum(v); }; -out = db.mr_sort_out; +let out = db.mr_sort_out; assert.commandWorked(t.mapReduce(m, r, out.getName())); assert.eq([{_id: "a", value: 55}], out.find().toArray(), "A1"); out.drop(); diff --git a/jstests/core/query/ne/ne1.js b/jstests/core/query/ne/ne1.js index 5069637eb30..5135294a433 100644 --- a/jstests/core/query/ne/ne1.js +++ b/jstests/core/query/ne/ne1.js @@ -1,4 +1,4 @@ -t = db.ne1; +let t = db.ne1; t.drop(); t.save({x: 1}); diff --git a/jstests/core/query/ne/ne2.js b/jstests/core/query/ne/ne2.js index 8f2b3d52f4c..4c8654560d3 100644 --- a/jstests/core/query/ne/ne2.js +++ b/jstests/core/query/ne/ne2.js @@ -3,7 +3,7 @@ // assumes_read_concern_local, // ] -t = db.jstests_ne2; +let t = db.jstests_ne2; t.drop(); t.createIndex({a: 1}); @@ -12,7 +12,7 @@ t.save({a: 0}); t.save({a: 0}); t.save({a: 0.5}); -e = t.find({a: {$ne: 0}}).explain(true); +let e = t.find({a: {$ne: 0}}).explain(true); assert.eq(2, e.executionStats.nReturned, 'A'); e = t.find({a: {$gt: -1, $lt: 1, $ne: 0}}).explain(true); diff --git a/jstests/core/query/ne/ne3.js b/jstests/core/query/ne/ne3.js index 5c38858c019..ccdb06a357f 100644 --- a/jstests/core/query/ne/ne3.js +++ b/jstests/core/query/ne/ne3.js @@ -1,6 +1,6 @@ // don't allow most operators with regex -t = db.jstests_ne3; +let t = db.jstests_ne3; t.drop(); assert.throws(function() { diff --git a/jstests/core/query/nin/nin.js b/jstests/core/query/nin/nin.js index b9887e48828..f327bb1315b 100644 --- a/jstests/core/query/nin/nin.js +++ b/jstests/core/query/nin/nin.js @@ -1,6 +1,6 @@ // @tags: [requires_fastcount] -t = db.jstests_nin; +let t = db.jstests_nin; t.drop(); function checkEqual(name, key, value) { @@ -16,7 +16,7 @@ function checkEqual(name, key, value) { " != " + t.find().count()); } -doTest = function(n) { +let doTest = function(n) { t.save({a: [1, 2, 3]}); t.save({a: [1, 2, 4]}); t.save({a: [1, 8, 5]}); diff --git a/jstests/core/query/nin/nin2.js b/jstests/core/query/nin/nin2.js index d134f5ad4a4..de373c71190 100644 --- a/jstests/core/query/nin/nin2.js +++ b/jstests/core/query/nin/nin2.js @@ -2,13 +2,13 @@ // Check that $nin is the opposite of $in SERVER-3264 -t = db.jstests_nin2; +let t = db.jstests_nin2; t.drop(); // Check various operator types. function checkOperators(array, inMatches) { - inCount = inMatches ? 1 : 0; - notInCount = 1 - inCount; + let inCount = inMatches ? 1 : 0; + let notInCount = 1 - inCount; assert.eq(inCount, t.count({foo: {$in: array}})); assert.eq(notInCount, t.count({foo: {$not: {$in: array}}})); assert.eq(notInCount, t.count({foo: {$nin: array}})); diff --git a/jstests/core/query/not/not1.js b/jstests/core/query/not/not1.js index 0726895ebbd..8ccfeaf7d87 100644 --- a/jstests/core/query/not/not1.js +++ b/jstests/core/query/not/not1.js @@ -1,6 +1,6 @@ // @tags: [requires_fastcount] -t = db.not1; +let t = db.not1; t.drop(); t.insert({a: 1}); diff --git a/jstests/core/query/number/numberint.js b/jstests/core/query/number/numberint.js index 55c923aea79..f6ed7b5b8d7 100644 --- a/jstests/core/query/number/numberint.js +++ b/jstests/core/query/number/numberint.js @@ -1,14 +1,14 @@ assert.eq.automsg("0", "new NumberInt()"); -n = new NumberInt(4); +let n = new NumberInt(4); assert.eq.automsg("4", "n"); assert.eq.automsg("4", "n.toNumber()"); assert.eq.automsg("8", "n + 4"); assert.eq.automsg("'NumberInt(4)'", "n.toString()"); assert.eq.automsg("'NumberInt(4)'", "tojson( n )"); -a = {}; +let a = {}; a.a = n; -p = tojson(a); +let p = tojson(a); assert.eq.automsg("'{ \"a\" : NumberInt(4) }'", "p"); assert.eq.automsg("NumberInt(4 )", "eval( tojson( NumberInt( 4 ) ) )"); @@ -63,12 +63,10 @@ assert(NumberInt(1), "to bool a"); // assert( ! NumberInt( 0 ) , "to bool b" ); // create doc with int value in db -t = db.getCollection("numberint"); +let t = db.getCollection("numberint"); t.drop(); -o = { - a: NumberInt(42) -}; +let o = {a: NumberInt(42)}; t.save(o); assert.eq(42, t.findOne().a, "save doc 1"); @@ -76,7 +74,7 @@ assert.eq(1, t.find({a: {$type: 16}}).count(), "save doc 2"); assert.eq(0, t.find({a: {$type: 1}}).count(), "save doc 3"); // roundtripping -mod = t.findOne({a: 42}); +let mod = t.findOne({a: 42}); mod.a += 10; mod.b = "foo"; delete mod._id; diff --git a/jstests/core/query/number/numberlong.js b/jstests/core/query/number/numberlong.js index a7dfd014539..d3477fd9ce0 100644 --- a/jstests/core/query/number/numberlong.js +++ b/jstests/core/query/number/numberlong.js @@ -1,14 +1,14 @@ assert.eq.automsg("0", "new NumberLong()"); -n = new NumberLong(4); +let n = new NumberLong(4); assert.eq.automsg("4", "n"); assert.eq.automsg("4", "n.toNumber()"); assert.eq.automsg("8", "n + 4"); assert.eq.automsg("'NumberLong(4)'", "n.toString()"); assert.eq.automsg("'NumberLong(4)'", "tojson( n )"); -a = {}; +let a = {}; a.a = n; -p = tojson(a); +let p = tojson(a); assert.eq.automsg("'{ \"a\" : NumberLong(4) }'", "p"); assert.eq.automsg("NumberLong(4 )", "eval( tojson( NumberLong( 4 ) ) )"); diff --git a/jstests/core/query/number/numberlong2.js b/jstests/core/query/number/numberlong2.js index be254027b79..6d04ddd84e9 100644 --- a/jstests/core/query/number/numberlong2.js +++ b/jstests/core/query/number/numberlong2.js @@ -4,7 +4,7 @@ // Test precision of NumberLong values with v1 index code SERVER-3717 -t = db.jstests_numberlong2; +let t = db.jstests_numberlong2; t.drop(); t.createIndex({x: 1}); @@ -24,8 +24,8 @@ chk(NumberLong("4503599627370497")); t.remove({}); -s = "11235399833116571"; -for (i = 99; i >= 0; --i) { +let s = "11235399833116571"; +for (let i = 99; i >= 0; --i) { t.save({x: NumberLong(s + i)}); } diff --git a/jstests/core/query/number/numberlong3.js b/jstests/core/query/number/numberlong3.js index 0dabdec2a05..ac89075ee75 100644 --- a/jstests/core/query/number/numberlong3.js +++ b/jstests/core/query/number/numberlong3.js @@ -1,26 +1,26 @@ // Test sorting with long longs and doubles - SERVER-3719 -t = db.jstests_numberlong3; +let t = db.jstests_numberlong3; t.drop(); -s = "11235399833116571"; -for (i = 10; i >= 0; --i) { - n = NumberLong(s + i); +let s = "11235399833116571"; +for (let i = 10; i >= 0; --i) { + let n = NumberLong(s + i); t.save({x: n}); if (0) { // SERVER-3719 t.save({x: n.floatApprox}); } } -ret = t.find().sort({x: 1}).toArray().filter(function(x) { +let ret = t.find().sort({x: 1}).toArray().filter(function(x) { return typeof (x.x.floatApprox) != 'undefined'; }); // printjson( ret ); -for (i = 1; i < ret.length; ++i) { - first = ret[i - 1].x.toString(); - second = ret[i].x.toString(); +for (let i = 1; i < ret.length; ++i) { + let first = ret[i - 1].x.toString(); + let second = ret[i].x.toString(); if (first.length == second.length) { assert.lte(ret[i - 1].x.toString(), ret[i].x.toString()); } diff --git a/jstests/core/query/number/numberlong4.js b/jstests/core/query/number/numberlong4.js index d7d73898b34..2cd381cc61c 100644 --- a/jstests/core/query/number/numberlong4.js +++ b/jstests/core/query/number/numberlong4.js @@ -1,7 +1,7 @@ // Test handling of comparison between long longs and their double approximations in btrees - // SERVER-3719. -t = db.jstests_numberlong4; +let t = db.jstests_numberlong4; t.drop(); if (0) { // SERVER-3719 @@ -10,9 +10,9 @@ if (0) { // SERVER-3719 Random.setRandomSeed(); - s = "11235399833116571"; - for (i = 0; i < 10000; ++i) { - n = NumberLong(s + Random.randInt(10)); + let s = "11235399833116571"; + for (let i = 0; i < 10000; ++i) { + let n = NumberLong(s + Random.randInt(10)); t.insert({x: (Random.randInt(2) ? n : n.floatApprox)}); } diff --git a/jstests/core/query/objid/objid1.js b/jstests/core/query/objid/objid1.js index d08089c26db..5c252a9531d 100644 --- a/jstests/core/query/objid/objid1.js +++ b/jstests/core/query/objid/objid1.js @@ -1,18 +1,16 @@ -t = db.objid1; +let t = db.objid1; t.drop(); -b = new ObjectId(); +let b = new ObjectId(); assert(b.str, "A"); -a = new ObjectId(b.str); +let a = new ObjectId(b.str); assert.eq(a.str, b.str, "B"); t.save({a: a}); assert(t.findOne().a.isObjectId, "C"); assert.eq(a.str, t.findOne().a.str, "D"); -x = { - a: new ObjectId() -}; +let x = {a: new ObjectId()}; eval(" y = " + tojson(x)); assert.eq(x.a.str, y.a.str, "E"); diff --git a/jstests/core/query/objid/objid2.js b/jstests/core/query/objid/objid2.js index 247843b587b..d25b1a6d9dc 100644 --- a/jstests/core/query/objid/objid2.js +++ b/jstests/core/query/objid/objid2.js @@ -1,4 +1,4 @@ -t = db.objid2; +let t = db.objid2; t.drop(); t.save({_id: 517, a: "hello"}); diff --git a/jstests/core/query/objid/objid3.js b/jstests/core/query/objid/objid3.js index 12d45530e52..79e495e25cb 100644 --- a/jstests/core/query/objid/objid3.js +++ b/jstests/core/query/objid/objid3.js @@ -1,4 +1,4 @@ -t = db.objid3; +let t = db.objid3; t.drop(); t.save({a: "bob", _id: 517}); diff --git a/jstests/core/query/objid/objid4.js b/jstests/core/query/objid/objid4.js index 7513e077029..de82d397b58 100644 --- a/jstests/core/query/objid/objid4.js +++ b/jstests/core/query/objid/objid4.js @@ -1,13 +1,11 @@ - - -o = new ObjectId(); +let o = new ObjectId(); assert(o.str); -a = new ObjectId(o.str); +let a = new ObjectId(o.str); assert.eq(o.str, a.str); assert.eq(a.str, a.str.toString()); -b = ObjectId(o.str); +let b = ObjectId(o.str); assert.eq(o.str, b.str); assert.eq(b.str, b.str.toString()); diff --git a/jstests/core/query/objid/objid5.js b/jstests/core/query/objid/objid5.js index c656b286f5b..c8599509c86 100644 --- a/jstests/core/query/objid/objid5.js +++ b/jstests/core/query/objid/objid5.js @@ -1,11 +1,11 @@ -t = db.objid5; +let t = db.objid5; t.drop(); t.save({_id: 5.5}); assert.eq(18, Object.bsonsize(t.findOne()), "A"); -x = db.runCommand({features: 1}); -y = db.runCommand({features: 1, oidReset: 1}); +let x = db.runCommand({features: 1}); +let y = db.runCommand({features: 1, oidReset: 1}); if (!x.ok) print("x: " + tojson(x)); diff --git a/jstests/core/query/objid/objid7.js b/jstests/core/query/objid/objid7.js index 4c3505f8965..2fc289b6000 100644 --- a/jstests/core/query/objid/objid7.js +++ b/jstests/core/query/objid/objid7.js @@ -1,7 +1,6 @@ - -a = new ObjectId("4c1a478603eba73620000000"); -b = new ObjectId("4c1a478603eba73620000000"); -c = new ObjectId(); +let a = new ObjectId("4c1a478603eba73620000000"); +let b = new ObjectId("4c1a478603eba73620000000"); +let c = new ObjectId(); assert.eq(a.toString(), b.toString(), "A"); assert.eq(a.toString(), "ObjectId(\"4c1a478603eba73620000000\")", "B"); diff --git a/jstests/core/query/or/or1.js b/jstests/core/query/or/or1.js index d90947d5f87..df3f1eb0ac4 100644 --- a/jstests/core/query/or/or1.js +++ b/jstests/core/query/or/or1.js @@ -1,22 +1,22 @@ -t = db.jstests_or1; +let t = db.jstests_or1; t.drop(); -checkArrs = function(a, b) { +let checkArrs = function(a, b) { assert.eq(a.length, b.length); - aStr = []; - bStr = []; + let aStr = []; + let bStr = []; a.forEach(function(x) { aStr.push(tojson(x)); }); b.forEach(function(x) { bStr.push(tojson(x)); }); - for (i = 0; i < aStr.length; ++i) { + for (let i = 0; i < aStr.length; ++i) { assert.neq(-1, bStr.indexOf(aStr[i])); } }; -doTest = function() { +let doTest = function() { t.save({_id: 0, a: 1}); t.save({_id: 1, a: 2}); t.save({_id: 2, b: 1}); @@ -36,10 +36,10 @@ doTest = function() { t.find({$or: ["a"]}).toArray(); }); - a1 = t.find({$or: [{a: 1}]}).toArray(); + let a1 = t.find({$or: [{a: 1}]}).toArray(); checkArrs([{_id: 0, a: 1}, {_id: 4, a: 1, b: 1}, {_id: 5, a: 1, b: 2}], a1); - a1b2 = t.find({$or: [{a: 1}, {b: 2}]}).toArray(); + let a1b2 = t.find({$or: [{a: 1}, {b: 2}]}).toArray(); checkArrs( [ {_id: 0, a: 1}, diff --git a/jstests/core/query/or/or5.js b/jstests/core/query/or/or5.js index 1843c3d6cb7..ba4f529359c 100644 --- a/jstests/core/query/or/or5.js +++ b/jstests/core/query/or/or5.js @@ -2,7 +2,7 @@ // requires_getmore, // ] -t = db.jstests_or5; +let t = db.jstests_or5; t.drop(); t.createIndex({a: 1}); @@ -28,7 +28,7 @@ assert.eq.automsg("6", "t.find( {$or:[{a:6},{b:3},{c:4}]} ).toArray().length"); assert.eq.automsg("6", "t.find( {$or:[{a:2},{b:6},{c:4}]} ).toArray().length"); assert.eq.automsg("6", "t.find( {$or:[{a:2},{b:3},{c:6}]} ).toArray().length"); -for (i = 2; i <= 7; ++i) { +for (var i = 2; i <= 7; ++i) { assert.eq.automsg("7", "t.find( {$or:[{a:2},{b:3},{c:4}]} ).batchSize( i ).toArray().length"); assert.eq.automsg("6", "t.find( {$or:[{a:6},{b:3},{c:4}]} ).batchSize( i ).toArray().length"); assert.eq.automsg("6", "t.find( {$or:[{a:2},{b:6},{c:4}]} ).batchSize( i ).toArray().length"); diff --git a/jstests/core/query/or/or7.js b/jstests/core/query/or/or7.js index e639a195739..414fbff858e 100644 --- a/jstests/core/query/or/or7.js +++ b/jstests/core/query/or/or7.js @@ -1,6 +1,6 @@ // @tags: [requires_non_retryable_writes] -t = db.jstests_or7; +let t = db.jstests_or7; t.drop(); t.createIndex({a: 1}); diff --git a/jstests/core/query/or/or8.js b/jstests/core/query/or/or8.js index f33ef3146ce..00d1ea0cbed 100644 --- a/jstests/core/query/or/or8.js +++ b/jstests/core/query/or/or8.js @@ -4,7 +4,7 @@ // missing collection -t = db.jstests_or8; +let t = db.jstests_or8; t.drop(); t.find({"$or": [{"PropA": {"$lt": "b"}}, {"PropA": {"$lt": "b", "$gt": "a"}}]}).toArray(); diff --git a/jstests/core/query/or/or9.js b/jstests/core/query/or/or9.js index 4938e84ca04..bcd527bb601 100644 --- a/jstests/core/query/or/or9.js +++ b/jstests/core/query/or/or9.js @@ -2,7 +2,7 @@ // index skipping and previous index range negation -t = db.jstests_or9; +let t = db.jstests_or9; t.drop(); t.createIndex({a: 1, b: 1}); diff --git a/jstests/core/query/or/orc.js b/jstests/core/query/or/orc.js index 001d6f4bc9f..bb632e0ce6c 100644 --- a/jstests/core/query/or/orc.js +++ b/jstests/core/query/or/orc.js @@ -1,7 +1,7 @@ // @tags: [requires_non_retryable_writes] // test that or duplicates are dropped in certain special cases -t = db.jstests_orc; +let t = db.jstests_orc; t.drop(); // The goal here will be to ensure the full range of valid values is scanned for each or clause, in diff --git a/jstests/core/query/or/ore.js b/jstests/core/query/or/ore.js index 756db6215c5..775d5e3b2c1 100644 --- a/jstests/core/query/or/ore.js +++ b/jstests/core/query/or/ore.js @@ -1,7 +1,7 @@ // verify that index direction is considered when deduping based on an earlier // index -t = db.jstests_ore; +let t = db.jstests_ore; t.drop(); t.createIndex({a: -1}); diff --git a/jstests/core/query/or/org.js b/jstests/core/query/or/org.js index 0c6808330c8..4780c54582b 100644 --- a/jstests/core/query/or/org.js +++ b/jstests/core/query/or/org.js @@ -2,7 +2,7 @@ // SERVER-2282 $or de duping with sparse indexes -t = db.jstests_org; +let t = db.jstests_org; t.drop(); t.createIndex({a: 1}, {sparse: true}); diff --git a/jstests/core/query/or/orh.js b/jstests/core/query/or/orh.js index 91ce121e5a4..9a870cf27b1 100644 --- a/jstests/core/query/or/orh.js +++ b/jstests/core/query/or/orh.js @@ -2,7 +2,7 @@ // SERVER-2831 Demonstration of sparse index matching semantics in a multi index $or query. -t = db.jstests_orh; +let t = db.jstests_orh; t.drop(); t.createIndex({a: 1}, {sparse: true}); diff --git a/jstests/core/query/or/orj.js b/jstests/core/query/or/orj.js index 6aabb3c39c7..9ff2288dc6b 100644 --- a/jstests/core/query/or/orj.js +++ b/jstests/core/query/or/orj.js @@ -1,6 +1,6 @@ // Test nested $or clauses SERVER-2585 SERVER-3192 -t = db.jstests_orj; +let t = db.jstests_orj; t.drop(); t.save({a: 1, b: 2}); diff --git a/jstests/core/query/or/ork.js b/jstests/core/query/or/ork.js index 8ce2346b6f3..525181f9061 100644 --- a/jstests/core/query/or/ork.js +++ b/jstests/core/query/or/ork.js @@ -1,6 +1,6 @@ // SERVER-2585 Test $or clauses within indexed top level $or clauses. -t = db.jstests_ork; +let t = db.jstests_ork; t.drop(); t.createIndex({a: 1}); diff --git a/jstests/core/query/or/oro.js b/jstests/core/query/or/oro.js index 5ceda73818e..43bd0b87a81 100644 --- a/jstests/core/query/or/oro.js +++ b/jstests/core/query/or/oro.js @@ -5,26 +5,26 @@ // Test $or query with several clauses on separate indexes. -t = db.jstests_oro; +let t = db.jstests_oro; t.drop(); -orClauses = []; -for (idxKey = 'a'; idxKey <= 'aaaaaaaaaa'; idxKey += 'a') { - idx = {}; +let orClauses = []; +for (let idxKey = 'a'; idxKey <= 'aaaaaaaaaa'; idxKey += 'a') { + let idx = {}; idx[idxKey] = 1; t.createIndex(idx); - for (i = 0; i < 200; ++i) { + for (let i = 0; i < 200; ++i) { t.insert(idx); } orClauses.push(idx); } printjson(t.find({$or: orClauses}).explain()); -c = t.find({$or: orClauses}).batchSize(100); -count = 0; +let c = t.find({$or: orClauses}).batchSize(100); +let count = 0; while (c.hasNext()) { - for (i = 0; i < 50 && c.hasNext(); ++i, c.next(), ++count) + for (let i = 0; i < 50 && c.hasNext(); ++i, c.next(), ++count) ; // Interleave with another operation. t.stats(); diff --git a/jstests/core/query/plan_cache/plan_cache_clear.js b/jstests/core/query/plan_cache/plan_cache_clear.js index d03330ab08e..afc53155fd5 100644 --- a/jstests/core/query/plan_cache/plan_cache_clear.js +++ b/jstests/core/query/plan_cache/plan_cache_clear.js @@ -25,6 +25,7 @@ 'use strict'; load("jstests/libs/sbe_util.js"); // For checkSBEEnabled. +load("jstests/libs/fixture_helpers.js"); const coll = db.jstests_plan_cache_clear; coll.drop(); @@ -228,8 +229,8 @@ assert.eq(0, numPlanCacheEntries(coll), dumpPlanCacheState(coll)); // Run reIndex on the collection. // Confirm that cache is empty. // (Only standalone mode supports the reIndex command.) -const isMongos = db.adminCommand({isdbgrid: 1}).isdbgrid; -const isStandalone = !isMongos && !db.runCommand({hello: 1}).hasOwnProperty('setName'); +const isStandalone = + !FixtureHelpers.isMongos(db) && !db.runCommand({hello: 1}).hasOwnProperty('setName'); if (isStandalone) { assert.eq(1, coll.find({a: 1, b: 1}).itcount()); assert.eq(1, numPlanCacheEntries(coll), dumpPlanCacheState(coll)); diff --git a/jstests/core/query/project/proj_key1.js b/jstests/core/query/project/proj_key1.js index c4834ffad49..0d6423156e0 100644 --- a/jstests/core/query/project/proj_key1.js +++ b/jstests/core/query/project/proj_key1.js @@ -2,12 +2,12 @@ // requires_getmore, // ] -t = db.proj_key1; +let t = db.proj_key1; t.drop(); -as = []; +let as = []; -for (i = 0; i < 10; i++) { +for (let i = 0; i < 10; i++) { as.push({a: i}); t.insert({a: i, b: i}); } diff --git a/jstests/core/query/pull/pull.js b/jstests/core/query/pull/pull.js index 612c65f9e65..c5d1519f2aa 100644 --- a/jstests/core/query/pull/pull.js +++ b/jstests/core/query/pull/pull.js @@ -3,7 +3,7 @@ // key. // @tags: [assumes_unsharded_collection] -t = db.jstests_pull; +let t = db.jstests_pull; t.drop(); t.save({a: [1, 2, 3]}); diff --git a/jstests/core/query/pull/pull2.js b/jstests/core/query/pull/pull2.js index a1b79955bb0..f3c04d517ca 100644 --- a/jstests/core/query/pull/pull2.js +++ b/jstests/core/query/pull/pull2.js @@ -3,7 +3,7 @@ // key. // @tags: [assumes_unsharded_collection, requires_fastcount] -t = db.pull2; +let t = db.pull2; t.drop(); t.save({a: [{x: 1}, {x: 1, b: 2}]}); diff --git a/jstests/core/query/pull/pull_or.js b/jstests/core/query/pull/pull_or.js index 9ef1e091d29..42b0d93bb15 100644 --- a/jstests/core/query/pull/pull_or.js +++ b/jstests/core/query/pull/pull_or.js @@ -3,13 +3,10 @@ // key. // @tags: [assumes_unsharded_collection] -t = db.pull_or; +let t = db.pull_or; t.drop(); -doc = { - _id: 1, - a: {b: [{x: 1}, {y: 'y'}, {x: 2}, {z: 'z'}]} -}; +let doc = {_id: 1, a: {b: [{x: 1}, {y: 'y'}, {x: 2}, {z: 'z'}]}}; t.insert(doc); diff --git a/jstests/core/query/pull/pull_remove1.js b/jstests/core/query/pull/pull_remove1.js index ab9368bab3b..307d84f2371 100644 --- a/jstests/core/query/pull/pull_remove1.js +++ b/jstests/core/query/pull/pull_remove1.js @@ -3,13 +3,10 @@ // key. // @tags: [assumes_unsharded_collection] -t = db.pull_remove1; +let t = db.pull_remove1; t.drop(); -o = { - _id: 1, - a: [1, 2, 3, 4, 5, 6, 7, 8] -}; +let o = {_id: 1, a: [1, 2, 3, 4, 5, 6, 7, 8]}; t.insert(o); assert.eq(o, t.findOne(), "A1"); diff --git a/jstests/core/query/pull/pullall.js b/jstests/core/query/pull/pullall.js index 2cd0872b079..7679bc6db71 100644 --- a/jstests/core/query/pull/pullall.js +++ b/jstests/core/query/pull/pullall.js @@ -3,7 +3,7 @@ // key. // @tags: [assumes_unsharded_collection] -t = db.jstests_pullall; +let t = db.jstests_pullall; t.drop(); t.save({a: [1, 2, 3]}); diff --git a/jstests/core/query/pull/pullall2.js b/jstests/core/query/pull/pullall2.js index 10e8c89caa1..e1bc26cb0bd 100644 --- a/jstests/core/query/pull/pullall2.js +++ b/jstests/core/query/pull/pullall2.js @@ -3,14 +3,11 @@ // key. // @tags: [assumes_unsharded_collection] -t = db.pullall2; +let t = db.pullall2; t.drop(); -o = { - _id: 1, - a: [] -}; -for (i = 0; i < 5; i++) +let o = {_id: 1, a: []}; +for (let i = 0; i < 5; i++) o.a.push({x: i, y: i}); t.insert(o); diff --git a/jstests/core/query/push/push2.js b/jstests/core/query/push/push2.js index 10669aa2581..0e00617b1ec 100644 --- a/jstests/core/query/push/push2.js +++ b/jstests/core/query/push/push2.js @@ -1,14 +1,14 @@ (function() { -t = db.push2; +let t = db.push2; t.drop(); t.save({_id: 1, a: []}); -s = new Array(700000).toString(); +let s = new Array(700000).toString(); -gotError = null; +let gotError = null; -for (x = 0; x < 100; x++) { +for (let x = 0; x < 100; x++) { print(x + " pushes"); var res = t.update({}, {$push: {a: s}}); gotError = res.hasWriteError(); diff --git a/jstests/core/query/push/push_sort.js b/jstests/core/query/push/push_sort.js index 2d74a3909f8..9ff12d5698c 100644 --- a/jstests/core/query/push/push_sort.js +++ b/jstests/core/query/push/push_sort.js @@ -7,7 +7,7 @@ // test exercises such $sort clause from the shell user's perspective. // -t = db.push_sort; +let t = db.push_sort; t.drop(); // diff --git a/jstests/core/query/query1.js b/jstests/core/query/query1.js index 7e16a03a8fc..08a31d88502 100644 --- a/jstests/core/query/query1.js +++ b/jstests/core/query/query1.js @@ -1,14 +1,14 @@ // @tags: [requires_fastcount] -t = db.query1; +let t = db.query1; t.drop(); t.save({num: 1}); t.save({num: 3}); t.save({num: 4}); -num = 0; -total = 0; +let num = 0; +let total = 0; t.find().forEach(function(z) { num++; diff --git a/jstests/core/query/queryoptimizera.js b/jstests/core/query/queryoptimizera.js index 2f3f2266847..42ca0032ea1 100644 --- a/jstests/core/query/queryoptimizera.js +++ b/jstests/core/query/queryoptimizera.js @@ -9,8 +9,8 @@ // constraint is printed at appropriate times. SERVER-5353 function numWarnings() { - logs = db.adminCommand({getLog: "global"}).log; - ret = 0; + let logs = db.adminCommand({getLog: "global"}).log; + let ret = 0; logs.forEach(function(x) { if (x.match(warningMatchRegexp)) { ++ret; @@ -19,23 +19,23 @@ function numWarnings() { return ret; } -collectionNameIndex = 0; +let collectionNameIndex = 0; // Generate a collection name not already present in the log. do { - testCollectionName = 'jstests_queryoptimizera__' + collectionNameIndex++; - warningMatchString = + var testCollectionName = 'jstests_queryoptimizera__' + collectionNameIndex++; + var warningMatchString = 'unindexed _id query on capped collection.*collection: test.' + testCollectionName; - warningMatchRegexp = new RegExp(warningMatchString); + var warningMatchRegexp = new RegExp(warningMatchString); } while (numWarnings() > 0); -t = db[testCollectionName]; +let t = db[testCollectionName]; t.drop(); -notCappedCollectionName = testCollectionName + '_notCapped'; +let notCappedCollectionName = testCollectionName + '_notCapped'; -notCapped = db.getSiblingDB("local").getCollection(notCappedCollectionName); +let notCapped = db.getSiblingDB("local").getCollection(notCappedCollectionName); notCapped.drop(); assert.commandWorked(db.createCollection(testCollectionName, {capped: true, size: 1000})); @@ -45,14 +45,14 @@ assert.commandWorked( t.insert({}); notCapped.insert({}); -oldNumWarnings = 0; +let oldNumWarnings = 0; function assertNoNewWarnings() { assert.eq(oldNumWarnings, numWarnings()); } function assertNewWarning() { - newNumWarnings = numWarnings(); + let newNumWarnings = numWarnings(); // Ensure that newNumWarnings > oldNumWarnings. It's not safe to test that oldNumWarnings + 1 // == newNumWarnings, because a (simulated) page fault exception may cause multiple messages to // be logged instead of only one. diff --git a/jstests/core/query/regex/regex.js b/jstests/core/query/regex/regex.js index 363a03db20c..409c69b0b59 100644 --- a/jstests/core/query/regex/regex.js +++ b/jstests/core/query/regex/regex.js @@ -1,16 +1,13 @@ // @tags: [ // assumes_read_concern_local, // ] +load("jstests/libs/fixture_helpers.js"); (function() { 'use strict'; const t = db.jstests_regex; -const hello = db.runCommand("hello"); -assert.commandWorked(hello); -const isMongos = (hello.msg === "isdbgrid"); - t.drop(); assert.commandWorked(t.save({a: "bcd"})); assert.eq(1, t.count({a: /b/}), "A"); @@ -48,7 +45,7 @@ assert.eq(1, t.count(query)); const result = t.find(query).explain(); assert.commandWorked(result); -if (!isMongos) { +if (!FixtureHelpers.isMongos(db)) { assert(result.hasOwnProperty("queryPlanner")); assert(result.queryPlanner.hasOwnProperty("parsedQuery"), tojson(result)); assert.eq(result.queryPlanner.parsedQuery, query); diff --git a/jstests/core/query/regex/regex2.js b/jstests/core/query/regex/regex2.js index 6ed1f2d290c..4801c7b8070 100644 --- a/jstests/core/query/regex/regex2.js +++ b/jstests/core/query/regex/regex2.js @@ -1,6 +1,6 @@ // @tags: [requires_fastcount] -t = db.regex2; +let t = db.regex2; t.drop(); assert.commandWorked(t.save({a: "test"})); @@ -15,8 +15,8 @@ assert.eq(2, t.find({a: /test/i}).count(), "F"); t.drop(); -a = "\u0442\u0435\u0441\u0442"; -b = "\u0422\u0435\u0441\u0442"; +let a = "\u0442\u0435\u0441\u0442"; +let b = "\u0422\u0435\u0441\u0442"; assert((new RegExp(a)).test(a), "B 1"); assert(!(new RegExp(a)).test(b), "B 2"); diff --git a/jstests/core/query/regex/regex3.js b/jstests/core/query/regex/regex3.js index b21a7a81435..c84f64020e4 100644 --- a/jstests/core/query/regex/regex3.js +++ b/jstests/core/query/regex/regex3.js @@ -3,7 +3,7 @@ // assumes_read_concern_local, // ] -t = db.regex3; +let t = db.regex3; t.drop(); assert.commandWorked(t.save({name: "eliot"})); diff --git a/jstests/core/query/regex/regex4.js b/jstests/core/query/regex/regex4.js index 0f7963fdd1e..d07614b1994 100644 --- a/jstests/core/query/regex/regex4.js +++ b/jstests/core/query/regex/regex4.js @@ -3,7 +3,7 @@ // assumes_read_concern_local, // ] -t = db.regex4; +let t = db.regex4; t.drop(); assert.commandWorked(t.save({name: "eliot"})); diff --git a/jstests/core/query/regex/regex5.js b/jstests/core/query/regex/regex5.js index d0836a62686..ea32b4864df 100644 --- a/jstests/core/query/regex/regex5.js +++ b/jstests/core/query/regex/regex5.js @@ -1,5 +1,5 @@ -t = db.regex5; +let t = db.regex5; t.drop(); // Add filler data to make sure that indexed solutions are @@ -11,10 +11,10 @@ for (var i = 0; i < 10; i++) { t.save({x: ["abc", "xyz1"]}); t.save({x: ["ac", "xyz2"]}); -a = /.*b.*c/; -x = /.*y.*/; +let a = /.*b.*c/; +let x = /.*y.*/; -doit = function() { +let doit = function() { assert.eq(1, t.find({x: a}).count(), "A"); assert.eq(2, t.find({x: x}).count(), "B"); assert.eq(2, t.find({x: {$in: [x]}}).count(), "C"); // SERVER-322 diff --git a/jstests/core/query/regex/regex6.js b/jstests/core/query/regex/regex6.js index cc7b507f610..168826bbae1 100644 --- a/jstests/core/query/regex/regex6.js +++ b/jstests/core/query/regex/regex6.js @@ -4,7 +4,7 @@ // @tags: [ // assumes_unsharded_collection, // ] -t = db.regex6; +let t = db.regex6; t.drop(); t.save({name: "eliot"}); diff --git a/jstests/core/query/regex/regex7.js b/jstests/core/query/regex/regex7.js index d89f914af4a..9a7e6153f1a 100644 --- a/jstests/core/query/regex/regex7.js +++ b/jstests/core/query/regex/regex7.js @@ -1,4 +1,4 @@ -t = db.regex_matches_self; +let t = db.regex_matches_self; t.drop(); t.insert({r: /^a/}); diff --git a/jstests/core/query/regex/regex8.js b/jstests/core/query/regex/regex8.js index 20164acf464..e57d01db067 100644 --- a/jstests/core/query/regex/regex8.js +++ b/jstests/core/query/regex/regex8.js @@ -1,4 +1,4 @@ -t = db.regex8; +let t = db.regex8; t.drop(); t.insert({_id: 1, a: "abc"}); diff --git a/jstests/core/query/regex/regex9.js b/jstests/core/query/regex/regex9.js index 96188d689dc..497b1cbdabc 100644 --- a/jstests/core/query/regex/regex9.js +++ b/jstests/core/query/regex/regex9.js @@ -1,5 +1,5 @@ -t = db.regex9; +let t = db.regex9; t.drop(); t.insert({_id: 1, a: ["a", "b", "c"]}); diff --git a/jstests/core/query/regex/regex_embed1.js b/jstests/core/query/regex/regex_embed1.js index 11d92a6f3dc..97a0cae6552 100644 --- a/jstests/core/query/regex/regex_embed1.js +++ b/jstests/core/query/regex/regex_embed1.js @@ -1,4 +1,4 @@ -t = db.regex_embed1; +let t = db.regex_embed1; t.drop(); diff --git a/jstests/core/query/regex/regexa.js b/jstests/core/query/regex/regexa.js index 694436e87a8..24ea8f90686 100644 --- a/jstests/core/query/regex/regexa.js +++ b/jstests/core/query/regex/regexa.js @@ -1,6 +1,6 @@ // Test simple regex optimization with a regex | (bar) present - SERVER-3298 -t = db.jstests_regexa; +let t = db.jstests_regexa; t.drop(); function check() { diff --git a/jstests/core/query/regex/regexb.js b/jstests/core/query/regex/regexb.js index 09e3518728b..398b9c5b836 100644 --- a/jstests/core/query/regex/regexb.js +++ b/jstests/core/query/regex/regexb.js @@ -1,6 +1,6 @@ // Test more than four regex expressions in a query -- SERVER-969 -t = db.jstests_regexb; +let t = db.jstests_regexb; t.drop(); t.save({a: 'a', b: 'b', c: 'c', d: 'd', e: 'e'}); diff --git a/jstests/core/query/rename/rename_operator.js b/jstests/core/query/rename/rename_operator.js index e86cc077e65..71965f269bd 100644 --- a/jstests/core/query/rename/rename_operator.js +++ b/jstests/core/query/rename/rename_operator.js @@ -11,7 +11,7 @@ * ] */ -t = db.jstests_rename_operator; +let t = db.jstests_rename_operator; t.drop(); function bad(f) { diff --git a/jstests/core/query/rename/rename_operator_missing_source.js b/jstests/core/query/rename/rename_operator_missing_source.js index ff219cda563..d9c087af9aa 100644 --- a/jstests/core/query/rename/rename_operator_missing_source.js +++ b/jstests/core/query/rename/rename_operator_missing_source.js @@ -8,7 +8,7 @@ * ] */ -t = db.jstests_rename5; +let t = db.jstests_rename5; t.drop(); t.createIndex({a: 1}); diff --git a/jstests/core/query/set/set1.js b/jstests/core/query/set/set1.js index bae41fc5803..6914ddc217f 100644 --- a/jstests/core/query/set/set1.js +++ b/jstests/core/query/set/set1.js @@ -1,5 +1,5 @@ -t = db.set1; +let t = db.set1; t.drop(); t.insert({_id: 1, emb: {}}); diff --git a/jstests/core/query/set/set2.js b/jstests/core/query/set/set2.js index c5b6e1c9553..9f37dd1e6b3 100644 --- a/jstests/core/query/set/set2.js +++ b/jstests/core/query/set/set2.js @@ -1,5 +1,5 @@ -t = db.set2; +let t = db.set2; t.drop(); t.save({_id: 1, x: true, y: {x: true}}); diff --git a/jstests/core/query/set/set3.js b/jstests/core/query/set/set3.js index 4af579fa0b9..6dab2e3df2b 100644 --- a/jstests/core/query/set/set3.js +++ b/jstests/core/query/set/set3.js @@ -3,12 +3,12 @@ // key. // @tags: [assumes_unsharded_collection] -t = db.set3; +let t = db.set3; t.drop(); t.insert({"test1": {"test2": {"abcdefghijklmnopqrstu": {"id": 1}}}}); t.update({}, {"$set": {"test1.test2.abcdefghijklmnopqrstuvwxyz": {"id": 2}}}); -x = t.findOne(); +let x = t.findOne(); assert.eq(1, x.test1.test2.abcdefghijklmnopqrstu.id, "A"); assert.eq(2, x.test1.test2.abcdefghijklmnopqrstuvwxyz.id, "B"); diff --git a/jstests/core/query/set/set4.js b/jstests/core/query/set/set4.js index 99c0913b977..c1ccb87d1a0 100644 --- a/jstests/core/query/set/set4.js +++ b/jstests/core/query/set/set4.js @@ -3,13 +3,10 @@ // key. // @tags: [assumes_unsharded_collection] -t = db.set4; +let t = db.set4; t.drop(); -orig = { - _id: 1, - a: [{x: 1}] -}; +let orig = {_id: 1, a: [{x: 1}]}; t.insert(orig); t.update({}, {$set: {'a.0.x': 2, 'foo.bar': 3}}); diff --git a/jstests/core/query/set/set5.js b/jstests/core/query/set/set5.js index a848899f4af..fbaa832c3a0 100644 --- a/jstests/core/query/set/set5.js +++ b/jstests/core/query/set/set5.js @@ -3,7 +3,7 @@ // key. // @tags: [assumes_unsharded_collection] -t = db.set5; +let t = db.set5; t.drop(); function check(want, err) { diff --git a/jstests/core/query/set/set6.js b/jstests/core/query/set/set6.js index 2f82eb40a68..ac96cee0228 100644 --- a/jstests/core/query/set/set6.js +++ b/jstests/core/query/set/set6.js @@ -3,13 +3,10 @@ // key. // @tags: [assumes_unsharded_collection] -t = db.set6; +let t = db.set6; t.drop(); -x = { - _id: 1, - r: new DBRef("foo", new ObjectId()) -}; +let x = {_id: 1, r: new DBRef("foo", new ObjectId())}; t.insert(x); assert.eq(x, t.findOne(), "A"); diff --git a/jstests/core/query/set/set7.js b/jstests/core/query/set/set7.js index e1cdd0f3bf2..232e3de5f8d 100644 --- a/jstests/core/query/set/set7.js +++ b/jstests/core/query/set/set7.js @@ -9,7 +9,7 @@ // test $set with array indicies -t = db.jstests_set7; +let t = db.jstests_set7; var res; t.drop(); diff --git a/jstests/core/query/sort/sort10.js b/jstests/core/query/sort/sort10.js index 6819c76fa5b..4369a179fcf 100644 --- a/jstests/core/query/sort/sort10.js +++ b/jstests/core/query/sort/sort10.js @@ -2,7 +2,7 @@ // // @tags: [requires_fastcount] -t = db.sort10; +let t = db.sort10; function checkSorting1(opts) { t.drop(); @@ -20,25 +20,26 @@ checkSorting1({}); checkSorting1({"background": true}); function checkSorting2(dates, sortOrder) { - cur = t.find().sort({x: sortOrder}); + let cur = t.find().sort({x: sortOrder}); assert.eq(dates.length, cur.count(), "Incorrect number of results returned"); - index = 0; + let index = 0; while (cur.hasNext()) { - date = cur.next().x; + let date = cur.next().x; assert.eq(dates[index].valueOf(), date.valueOf()); index++; } } t.drop(); -dates = [new Date(-5000000000000), new Date(5000000000000), new Date(0), new Date(5), new Date(-5)]; +let dates = + [new Date(-5000000000000), new Date(5000000000000), new Date(0), new Date(5), new Date(-5)]; for (var i = 0; i < dates.length; i++) { t.insert({x: dates[i]}); } dates.sort(function(a, b) { return a - b; }); -reverseDates = dates.slice(0).reverse(); +let reverseDates = dates.slice(0).reverse(); checkSorting2(dates, 1); checkSorting2(reverseDates, -1); diff --git a/jstests/core/query/sort/sort2.js b/jstests/core/query/sort/sort2.js index 1d373193fcc..38dd69921c8 100644 --- a/jstests/core/query/sort/sort2.js +++ b/jstests/core/query/sort/sort2.js @@ -1,5 +1,5 @@ // test sorting, mainly a test ver simple with no index -t = db.sort2; +let t = db.sort2; t.drop(); t.save({x: 1, y: {a: 5, b: 4}}); diff --git a/jstests/core/query/sort/sort6.js b/jstests/core/query/sort/sort6.js index f2658bbcbad..9198c2fc136 100644 --- a/jstests/core/query/sort/sort6.js +++ b/jstests/core/query/sort/sort6.js @@ -1,4 +1,4 @@ -t = db.sort6; +let t = db.sort6; function get(x) { return t.find().sort({c: x}).map(function(z) { diff --git a/jstests/core/query/sort/sort8.js b/jstests/core/query/sort/sort8.js index fa0b0040de1..ab40d4578e3 100644 --- a/jstests/core/query/sort/sort8.js +++ b/jstests/core/query/sort/sort8.js @@ -1,15 +1,15 @@ // Check sorting of arrays indexed by key SERVER-2884 -t = db.jstests_sort8; +let t = db.jstests_sort8; t.drop(); t.save({a: [1, 10]}); t.save({a: 5}); -unindexedForward = t.find().sort({a: 1}).toArray(); -unindexedReverse = t.find().sort({a: -1}).toArray(); +let unindexedForward = t.find().sort({a: 1}).toArray(); +let unindexedReverse = t.find().sort({a: -1}).toArray(); t.createIndex({a: 1}); -indexedForward = t.find().sort({a: 1}).hint({a: 1}).toArray(); -indexedReverse = t.find().sort({a: -1}).hint({a: 1}).toArray(); +let indexedForward = t.find().sort({a: 1}).hint({a: 1}).toArray(); +let indexedReverse = t.find().sort({a: -1}).hint({a: 1}).toArray(); assert.eq(unindexedForward, indexedForward); assert.eq(unindexedReverse, indexedReverse); diff --git a/jstests/core/query/sort/sort9.js b/jstests/core/query/sort/sort9.js index 57496b40da1..a606ec237fb 100644 --- a/jstests/core/query/sort/sort9.js +++ b/jstests/core/query/sort/sort9.js @@ -1,6 +1,6 @@ // Unindexed array sorting SERVER-2884 -t = db.jstests_sort9; +let t = db.jstests_sort9; t.drop(); t.save({a: []}); diff --git a/jstests/core/query/sort/sort_merge.js b/jstests/core/query/sort/sort_merge.js index fe6e24917d7..6612f52a6d4 100644 --- a/jstests/core/query/sort/sort_merge.js +++ b/jstests/core/query/sort/sort_merge.js @@ -114,7 +114,7 @@ function runTest(sorts, filters, verifyCallback) { // Check that there are no duplicates. let ids = new Set(); for (let doc of res) { - assert(!ids.has(doc._id), () => "Duplicate _id: " + tojson(_id)); + assert(!ids.has(doc._id), () => "Duplicate _id: " + tojson(doc._id)); ids.add(doc._id); } } diff --git a/jstests/core/query/sort/sort_merge_collation.js b/jstests/core/query/sort/sort_merge_collation.js index 38e6f33d9da..e4714718a76 100644 --- a/jstests/core/query/sort/sort_merge_collation.js +++ b/jstests/core/query/sort/sort_merge_collation.js @@ -74,7 +74,7 @@ function runTest(sorts, filters) { // Check that there are no duplicates. let ids = new Set(); for (let doc of res) { - assert(!ids.has(doc._id), () => "Duplicate _id: " + tojson(_id)); + assert(!ids.has(doc._id), () => "Duplicate _id: " + tojson(doc._id)); ids.add(doc._id); } } diff --git a/jstests/core/query/sort/sort_numeric.js b/jstests/core/query/sort/sort_numeric.js index 5ff3e71a066..908a9e7184a 100644 --- a/jstests/core/query/sort/sort_numeric.js +++ b/jstests/core/query/sort/sort_numeric.js @@ -1,5 +1,5 @@ -t = db.sort_numeric; +let t = db.sort_numeric; t.drop(); // there are two numeric types int he db; make sure it handles them right @@ -18,7 +18,7 @@ for (var pass = 0; pass < 2; pass++) { var c = t.find().sort({a: 1}); var last = 0; while (c.hasNext()) { - current = c.next(); + let current = c.next(); assert(current.a > last); last = current.a; } diff --git a/jstests/core/query/sort/sortd.js b/jstests/core/query/sort/sortd.js index 525f08ea947..39aacb77331 100644 --- a/jstests/core/query/sort/sortd.js +++ b/jstests/core/query/sort/sortd.js @@ -4,12 +4,12 @@ // Test sorting with dups and multiple candidate query plans. -t = db.jstests_sortd; +let t = db.jstests_sortd; function checkNumSorted(n, query) { - docs = query.toArray(); + let docs = query.toArray(); assert.eq(n, docs.length); - for (i = 1; i < docs.length; ++i) { + for (let i = 1; i < docs.length; ++i) { assert.lte(docs[i - 1].a, docs[i].a); } } @@ -31,10 +31,10 @@ t.drop(); t.save({a: 1}); t.save({a: 10}); -for (i = 2; i <= 9; ++i) { +for (let i = 2; i <= 9; ++i) { t.save({a: i}); } -for (i = 0; i < 30; ++i) { +for (let i = 0; i < 30; ++i) { t.save({a: 100}); } t.createIndex({a: 1}); @@ -49,10 +49,10 @@ t.drop(); t.save({a: 1}); t.save({a: 200}); -for (i = 2; i <= 199; ++i) { +for (let i = 2; i <= 199; ++i) { t.save({a: i}); } -for (i = 0; i < 30; ++i) { +for (let i = 0; i < 30; ++i) { t.save({a: 2000}); } t.createIndex({a: 1}); @@ -65,7 +65,7 @@ checkNumSorted(200, t.find({a: {$gte: 0, $lte: 200}, b: null}).sort({a: 1})); t.drop(); -for (i = 399; i >= 0; --i) { +for (let i = 399; i >= 0; --i) { t.save({a: i}); } t.createIndex({a: 1}); diff --git a/jstests/core/query/sort/sortf.js b/jstests/core/query/sort/sortf.js index b2506eff663..8efa55c794e 100644 --- a/jstests/core/query/sort/sortf.js +++ b/jstests/core/query/sort/sortf.js @@ -5,18 +5,18 @@ // Unsorted plan on {a:1}, sorted plan on {b:1}. The unsorted plan exhausts its memory limit before // the sorted plan is chosen by the query optimizer. -t = db.jstests_sortf; +let t = db.jstests_sortf; t.drop(); t.createIndex({a: 1}); t.createIndex({b: 1}); -for (i = 0; i < 100; ++i) { +for (let i = 0; i < 100; ++i) { t.save({a: 0, b: 0}); } -big = new Array(10 * 1000 * 1000).toString(); -for (i = 0; i < 5; ++i) { +let big = new Array(10 * 1000 * 1000).toString(); +for (let i = 0; i < 5; ++i) { t.save({a: 1, b: 1, big: big}); } diff --git a/jstests/core/query/sort/sorti.js b/jstests/core/query/sort/sorti.js index e30739b4867..4816f83be7a 100644 --- a/jstests/core/query/sort/sorti.js +++ b/jstests/core/query/sort/sorti.js @@ -1,6 +1,6 @@ // Check that a projection is applied after an in memory sort. -t = db.jstests_sorti; +let t = db.jstests_sorti; t.drop(); t.save({a: 1, b: 0}); @@ -9,10 +9,10 @@ t.save({a: 2, b: 2}); t.save({a: 4, b: 3}); function checkBOrder(query) { - arr = query.toArray(); - order = []; - for (i in arr) { - a = arr[i]; + let arr = query.toArray(); + let order = []; + for (let i in arr) { + let a = arr[i]; order.push(a.b); } assert.eq([0, 2, 1, 3], order); diff --git a/jstests/core/query/sort/sortk.js b/jstests/core/query/sort/sortk.js index 1561d61675e..adb829d182d 100644 --- a/jstests/core/query/sort/sortk.js +++ b/jstests/core/query/sort/sortk.js @@ -8,7 +8,7 @@ // requires_scripting, // ] -t = db.jstests_sortk; +let t = db.jstests_sortk; t.drop(); function resetCollection() { @@ -25,7 +25,7 @@ resetCollection(); t.createIndex({a: 1, b: 1}); function simpleQuery(extraFields, sort, hint) { - query = {a: {$in: [1, 2]}}; + let query = {a: {$in: [1, 2]}}; Object.extend(query, extraFields); sort = sort || {b: 1}; hint = hint || {a: 1, b: 1}; @@ -67,7 +67,7 @@ assert.eq(0, simpleQuery({}, {a: -1, b: 1}).limit(-1)[0].b); // Without a hint, multiple cursors are attempted. assert.eq(0, t.find({a: {$in: [1, 2]}}).sort({b: 1}).limit(-1)[0].b); -explain = t.find({a: {$in: [1, 2]}}).sort({b: 1}).limit(-1).explain(true); +let explain = t.find({a: {$in: [1, 2]}}).sort({b: 1}).limit(-1).explain(true); assert.eq(1, explain.executionStats.nReturned); // The expected first result now comes from the first interval. diff --git a/jstests/core/query/type/type1.js b/jstests/core/query/type/type1.js index 8066de2a5c4..49674d834ea 100644 --- a/jstests/core/query/type/type1.js +++ b/jstests/core/query/type/type1.js @@ -1,6 +1,6 @@ // @tags: [requires_fastcount] -t = db.type1; +let t = db.type1; t.drop(); t.save({x: 1.1}); diff --git a/jstests/core/query/type/type2.js b/jstests/core/query/type/type2.js index b2b094d0652..701d99f816e 100644 --- a/jstests/core/query/type/type2.js +++ b/jstests/core/query/type/type2.js @@ -1,6 +1,6 @@ // SERVER-1735 $type:10 matches null value, not missing value. -t = db.jstests_type2; +let t = db.jstests_type2; t.drop(); t.save({a: null}); diff --git a/jstests/core/query/type/type3.js b/jstests/core/query/type/type3.js index 8b4858662dd..14c7697bc66 100644 --- a/jstests/core/query/type/type3.js +++ b/jstests/core/query/type/type3.js @@ -4,7 +4,7 @@ // Check query type bracketing SERVER-3222 -t = db.jstests_type3; +let t = db.jstests_type3; t.drop(); t.createIndex({a: 1}); diff --git a/jstests/core/query/unset/unset.js b/jstests/core/query/unset/unset.js index 14e18229723..c8e6ca501ef 100644 --- a/jstests/core/query/unset/unset.js +++ b/jstests/core/query/unset/unset.js @@ -1,10 +1,7 @@ -t = db.unset; +let t = db.unset; t.drop(); -orig = { - _id: 1, - emb: {} -}; +let orig = {_id: 1, emb: {}}; t.insert(orig); t.update({_id: 1}, {$unset: {'emb.a': 1}}); diff --git a/jstests/core/query/unset/unset2.js b/jstests/core/query/unset/unset2.js index e120ae2b674..4d192c5211e 100644 --- a/jstests/core/query/unset/unset2.js +++ b/jstests/core/query/unset/unset2.js @@ -5,7 +5,7 @@ var res; -t = db.unset2; +let t = db.unset2; t.drop(); t.save({a: ["a", "b", "c", "d"]}); diff --git a/jstests/core/query/where/where1.js b/jstests/core/query/where/where1.js index 1082bb902e8..d093388c3d1 100644 --- a/jstests/core/query/where/where1.js +++ b/jstests/core/query/where/where1.js @@ -3,7 +3,7 @@ // requires_scripting, // ] -t = db.getCollection("where1"); +let t = db.getCollection("where1"); t.drop(); t.save({a: 1}); diff --git a/jstests/core/query/where/where2.js b/jstests/core/query/where/where2.js index 6561c829353..12ba7382e3c 100644 --- a/jstests/core/query/where/where2.js +++ b/jstests/core/query/where/where2.js @@ -3,7 +3,7 @@ // requires_scripting, // ] -t = db.getCollection("where2"); +let t = db.getCollection("where2"); t.drop(); t.save({a: 1}); diff --git a/jstests/core/query/where/where3.js b/jstests/core/query/where/where3.js index ffbe690312c..3b48bab56f5 100644 --- a/jstests/core/query/where/where3.js +++ b/jstests/core/query/where/where3.js @@ -3,7 +3,7 @@ // requires_scripting // ] -t = db.where3; +let t = db.where3; t.drop(); t.save({returned_date: 5}); diff --git a/jstests/core/role_management_helpers.js b/jstests/core/role_management_helpers.js index 9fd3d28ce55..05e93f7a70d 100644 --- a/jstests/core/role_management_helpers.js +++ b/jstests/core/role_management_helpers.js @@ -13,7 +13,7 @@ // It is not a comprehensive test of the functionality of the role manipulation commands function assertHasRole(rolesArray, roleName, roleDB) { - for (i in rolesArray) { + for (let i in rolesArray) { var curRole = rolesArray[i]; if (curRole.role == roleName && curRole.db == roleDB) { return; @@ -23,7 +23,7 @@ function assertHasRole(rolesArray, roleName, roleDB) { } function assertHasPrivilege(privilegeArray, privilege) { - for (i in privilegeArray) { + for (let i in privilegeArray) { var curPriv = privilegeArray[i]; if (curPriv.resource.cluster == privilege.resource.cluster && curPriv.resource.anyResource == privilege.resource.anyResource && @@ -31,7 +31,7 @@ function assertHasPrivilege(privilegeArray, privilege) { curPriv.resource.collection == privilege.resource.collection) { // Same resource assert.eq(curPriv.actions.length, privilege.actions.length); - for (k in curPriv.actions) { + for (let k in curPriv.actions) { assert.eq(curPriv.actions[k], privilege.actions[k]); } return; diff --git a/jstests/core/server1470.js b/jstests/core/server1470.js index c3c7d47aaeb..bbca047d8ee 100644 --- a/jstests/core/server1470.js +++ b/jstests/core/server1470.js @@ -3,15 +3,12 @@ // key. // @tags: [assumes_unsharded_collection, requires_multi_updates, requires_non_retryable_writes] -t = db.server1470; +let t = db.server1470; t.drop(); -q = { - "name": "first", - "pic": {"$ref": "foo", "$id": ObjectId("4c48d04cd33a5a92628c9af6")} -}; +let q = {"name": "first", "pic": {"$ref": "foo", "$id": ObjectId("4c48d04cd33a5a92628c9af6")}}; t.update(q, {$set: {x: 1}}, true, true); -ref = t.findOne().pic; +let ref = t.findOne().pic; assert.eq("object", typeof (ref)); assert.eq(q.pic["$ref"], ref["$ref"]); assert.eq(q.pic["$id"], ref["$id"]); diff --git a/jstests/core/server5346.js b/jstests/core/server5346.js index 18f2f019e5e..f9ad6852961 100644 --- a/jstests/core/server5346.js +++ b/jstests/core/server5346.js @@ -1,11 +1,8 @@ -t = db.server5346; +let t = db.server5346; t.drop(); -x = { - _id: 1, - versions: {} -}; +let x = {_id: 1, versions: {}}; t.insert(x); t.update({_id: 1}, {$inc: {"versions.2_01": 1}}); diff --git a/jstests/core/server7756.js b/jstests/core/server7756.js index 844c3a40d4d..574e5587845 100644 --- a/jstests/core/server7756.js +++ b/jstests/core/server7756.js @@ -1,5 +1,5 @@ -t = db.server7756; +let t = db.server7756; t.drop(); t.save({a: [{1: 'x'}, 'y']}); diff --git a/jstests/core/server9385.js b/jstests/core/server9385.js index 4eb11076139..3e8cd4c96bd 100644 --- a/jstests/core/server9385.js +++ b/jstests/core/server9385.js @@ -2,11 +2,11 @@ // // @tags: [requires_fastcount] -t = db.server9385; +let t = db.server9385; t.drop(); t.insert({_id: 1, x: 1}); -x = t.findOne(); +let x = t.findOne(); x._id = 2; t.save(x); diff --git a/jstests/core/shell/shell1.js b/jstests/core/shell/shell1.js index 4fc4c3a1c15..cbe52f14401 100644 --- a/jstests/core/shell/shell1.js +++ b/jstests/core/shell/shell1.js @@ -1,4 +1,4 @@ -x = 1; +let x = 1; shellHelper("show", "tables;"); shellHelper("show", "tables"); diff --git a/jstests/core/shell/shellkillop.js b/jstests/core/shell/shellkillop.js index 0ac2ad681ed..b6c3746e052 100644 --- a/jstests/core/shell/shellkillop.js +++ b/jstests/core/shell/shellkillop.js @@ -1,15 +1,15 @@ -baseName = "jstests_shellkillop"; +let baseName = "jstests_shellkillop"; // 'retry' should be set to true in contexts where an exception should cause the test to be retried // rather than to fail. -retry = false; +let retry = false; function testShellAutokillop() { if (true) { // toggle to disable test db[baseName].drop(); print("shellkillop.js insert data"); - for (i = 0; i < 100000; ++i) { + for (let i = 0; i < 100000; ++i) { db[baseName].insert({i: 1}); } assert.eq(100000, db[baseName].count()); @@ -19,7 +19,7 @@ function testShellAutokillop() { var evalStr = "print('SKO subtask started'); db." + baseName + ".update( {}, {$set:{i:'abcdefghijkl'}}, false, true ); db." + baseName + ".count();"; print("shellkillop.js evalStr:" + evalStr); - spawn = startMongoProgramNoConnect( + let spawn = startMongoProgramNoConnect( "mongo", "--autokillop", "--port", myPort(), "--eval", evalStr); sleep(100); @@ -35,7 +35,7 @@ function testShellAutokillop() { print("count abcdefghijkl:" + db[baseName].find({i: 'abcdefghijkl'}).count()); var inprog = db.currentOp().inprog; - for (i in inprog) { + for (let i in inprog) { if (inprog[i].ns == "test." + baseName) throw Error("shellkillop.js op is still running: " + tojson(inprog[i])); } diff --git a/jstests/core/show_record_id.js b/jstests/core/show_record_id.js index 3af12d74d61..6bf75a42d37 100644 --- a/jstests/core/show_record_id.js +++ b/jstests/core/show_record_id.js @@ -8,8 +8,8 @@ var t = db.show_record_id; t.drop(); function checkResults(arr) { - for (i in arr) { - a = arr[i]; + for (let i in arr) { + let a = arr[i]; assert(a['$recordId']); } } diff --git a/jstests/core/splitvector.js b/jstests/core/splitvector.js index 5c3c1b2e559..54d8112ab97 100644 --- a/jstests/core/splitvector.js +++ b/jstests/core/splitvector.js @@ -26,14 +26,14 @@ // e.g. 20000 // @param maxChunkSize is in MBs. // -assertChunkSizes = function(splitVec, numDocs, maxChunkSize, msg) { +let assertChunkSizes = function(splitVec, numDocs, maxChunkSize, msg) { splitVec = [{x: -1}].concat(splitVec); splitVec.push({x: numDocs + 1}); - for (i = 0; i < splitVec.length - 1; i++) { - min = splitVec[i]; - max = splitVec[i + 1]; + for (let i = 0; i < splitVec.length - 1; i++) { + let min = splitVec[i]; + let max = splitVec[i + 1]; var avgObjSize = db.jstests_splitvector.stats().avgObjSize; - size = db.runCommand({datasize: "test.jstests_splitvector", min: min, max: max}).size; + let size = db.runCommand({datasize: "test.jstests_splitvector", min: min, max: max}).size; // It is okay for the last chunk to be smaller. A collection's size does not // need to be exactly a multiple of maxChunkSize. @@ -90,7 +90,7 @@ let bulkInsertDocsFixedX = function(coll, numDocs, filler, xVal) { // ------------------------- // TESTS START HERE // ------------------------- -f = db.jstests_splitvector; +let f = db.jstests_splitvector; resetCollection(); // ------------------------- @@ -125,29 +125,30 @@ assert.eq( resetCollection(); f.createIndex({x: 1}); +let filler; var case4 = function() { // Get baseline document size filler = ""; while (filler.length < 500) filler += "a"; f.save({x: 0, y: filler}); - docSize = db.runCommand({datasize: "test.jstests_splitvector"}).size; + let docSize = db.runCommand({datasize: "test.jstests_splitvector"}).size; assert.gt(docSize, 500, "4a"); // Fill collection and get split vector for 1MB maxChunkSize let numDocs = 4500; bulkInsertDocs(f, numDocs - 1, filler); // 1 document was already inserted. - res = db.runCommand( + let res = db.runCommand( {splitVector: "test.jstests_splitvector", keyPattern: {x: 1}, maxChunkSize: 1}); // splitVector aims at getting half-full chunks after split - factor = 0.5; + let factor = 0.5; assert.eq(true, res.ok, "4b"); assert.close( numDocs * docSize / ((1 << 20) * factor), res.splitKeys.length, "num split keys", -1); assertChunkSizes(res.splitKeys, numDocs, (1 << 20) * factor, "4d"); - for (i = 0; i < res.splitKeys.length; i++) { + for (let i = 0; i < res.splitKeys.length; i++) { assertFieldNamesMatch(res.splitKeys[i], {x: 1}); } }; @@ -162,7 +163,7 @@ f.createIndex({x: 1}); var case5 = function() { // Fill collection and get split vector for 1MB maxChunkSize bulkInsertDocs(f, 4499, filler); - res = db.runCommand({ + let res = db.runCommand({ splitVector: "test.jstests_splitvector", keyPattern: {x: 1}, maxChunkSize: 1, @@ -171,7 +172,7 @@ var case5 = function() { assert.eq(true, res.ok, "5a"); assert.eq(1, res.splitKeys.length, "5b"); - for (i = 0; i < res.splitKeys.length; i++) { + for (let i = 0; i < res.splitKeys.length; i++) { assertFieldNamesMatch(res.splitKeys[i], {x: 1}); } }; @@ -186,7 +187,7 @@ f.createIndex({x: 1}); var case6 = function() { // Fill collection and get split vector for 1MB maxChunkSize bulkInsertDocs(f, 1999, filler); - res = db.runCommand({ + let res = db.runCommand({ splitVector: "test.jstests_splitvector", keyPattern: {x: 1}, maxChunkSize: 1, @@ -195,7 +196,7 @@ var case6 = function() { assert.eq(true, res.ok, "6a"); assert.eq(3, res.splitKeys.length, "6b"); - for (i = 0; i < res.splitKeys.length; i++) { + for (let i = 0; i < res.splitKeys.length; i++) { assertFieldNamesMatch(res.splitKeys[i], {x: 1}); } }; @@ -212,12 +213,12 @@ var case7 = function() { // Fill collection and get split vector for 1MB maxChunkSize bulkInsertDocsFixedX(f, 2099, filler, 1); bulkInsertDocsFixedX(f, 9, filler, 2); - res = db.runCommand( + let res = db.runCommand( {splitVector: "test.jstests_splitvector", keyPattern: {x: 1}, maxChunkSize: 1}); assert.eq(true, res.ok, "7a"); assert.eq(2, res.splitKeys[0].x, "7b"); - for (i = 0; i < res.splitKeys.length; i++) { + for (let i = 0; i < res.splitKeys.length; i++) { assertFieldNamesMatch(res.splitKeys[i], {x: 1}); } }; @@ -234,14 +235,14 @@ var case8 = function() { bulkInsertDocsFixedX(f, 9, filler, 1); bulkInsertDocsFixedX(f, 2099, filler, 2); bulkInsertDocsFixedX(f, 9, filler, 3); - res = db.runCommand( + let res = db.runCommand( {splitVector: "test.jstests_splitvector", keyPattern: {x: 1}, maxChunkSize: 1}); assert.eq(true, res.ok, "8a"); assert.eq(2, res.splitKeys.length, "8b"); assert.eq(2, res.splitKeys[0].x, "8c"); assert.eq(3, res.splitKeys[1].x, "8d"); - for (i = 0; i < res.splitKeys.length; i++) { + for (let i = 0; i < res.splitKeys.length; i++) { assertFieldNamesMatch(res.splitKeys[i], {x: 1}); } }; @@ -262,7 +263,7 @@ var case9 = function() { assert.eq(3, f.count()); print(f.getFullName()); - res = db.runCommand({splitVector: f.getFullName(), keyPattern: {x: 1}, force: true}); + let res = db.runCommand({splitVector: f.getFullName(), keyPattern: {x: 1}, force: true}); assert.eq(true, res.ok, "9a"); assert.eq(1, res.splitKeys.length, "9b"); @@ -275,7 +276,7 @@ var case9 = function() { assert.eq(true, res.ok, "9a: " + tojson(res)); assert.eq(1, res.splitKeys.length, "9b: " + tojson(res)); assert.eq(2, res.splitKeys[0].x, "9c: " + tojson(res)); - for (i = 0; i < res.splitKeys.length; i++) { + for (let i = 0; i < res.splitKeys.length; i++) { assertFieldNamesMatch(res.splitKeys[i], {x: 1}); } } diff --git a/jstests/core/stage_debug/stages_and_hash.js b/jstests/core/stage_debug/stages_and_hash.js index 4e75dace007..741a6778ad6 100644 --- a/jstests/core/stage_debug/stages_and_hash.js +++ b/jstests/core/stage_debug/stages_and_hash.js @@ -6,7 +6,7 @@ // no_selinux, // ] -t = db.stages_and_hashed; +let t = db.stages_and_hashed; t.drop(); var collname = "stages_and_hashed"; @@ -21,7 +21,7 @@ t.createIndex({bar: 1}); t.createIndex({baz: 1}); // Scan foo <= 20 -ixscan1 = { +let ixscan1 = { ixscan: { args: { name: "stages_and_hashed", @@ -36,7 +36,7 @@ ixscan1 = { }; // Scan bar >= 40 -ixscan2 = { +let ixscan2 = { ixscan: { args: { name: "stages_and_hashed", @@ -52,15 +52,13 @@ ixscan2 = { // bar = 50 - foo // Intersection is (foo=0 bar=50, foo=1 bar=49, ..., foo=10 bar=40) -andix1ix2 = { - andHash: {args: {nodes: [ixscan1, ixscan2]}} -}; -res = db.runCommand({stageDebug: {plan: andix1ix2, collection: collname}}); +let andix1ix2 = {andHash: {args: {nodes: [ixscan1, ixscan2]}}}; +let res = db.runCommand({stageDebug: {plan: andix1ix2, collection: collname}}); assert.eq(res.ok, 1); assert.eq(res.results.length, 11); // Filter predicates from 2 indices. Tests that we union the idx info. -andix1ix2filter = { +let andix1ix2filter = { fetch: { filter: {bar: {$in: [45, 46, 48]}, foo: {$in: [4, 5, 6]}}, args: {node: {andHash: {args: {nodes: [ixscan1, ixscan2]}}}} diff --git a/jstests/core/stage_debug/stages_and_sorted.js b/jstests/core/stage_debug/stages_and_sorted.js index 34826baaa32..55c5abd8676 100644 --- a/jstests/core/stage_debug/stages_and_sorted.js +++ b/jstests/core/stage_debug/stages_and_sorted.js @@ -6,7 +6,7 @@ // no_selinux, // ] -t = db.stages_and_sorted; +let t = db.stages_and_sorted; t.drop(); var collname = "stages_and_sorted"; @@ -31,7 +31,7 @@ t.createIndex({bar: 1}); t.createIndex({baz: 1}); // Scan foo == 1 -ixscan1 = { +let ixscan1 = { ixscan: { args: { name: "stages_and_sorted", @@ -46,7 +46,7 @@ ixscan1 = { }; // Scan bar == 1 -ixscan2 = { +let ixscan2 = { ixscan: { args: { name: "stages_and_sorted", @@ -61,7 +61,7 @@ ixscan2 = { }; // Scan baz == 12 -ixscan3 = { +let ixscan3 = { ixscan: { args: { name: "stages_and_sorted", @@ -76,18 +76,14 @@ ixscan3 = { }; // Intersect foo==1 with bar==1 with baz==12. -andix1ix2 = { - andSorted: {args: {nodes: [ixscan1, ixscan2, ixscan3]}} -}; -res = db.runCommand({stageDebug: {collection: collname, plan: andix1ix2}}); +let andix1ix2 = {andSorted: {args: {nodes: [ixscan1, ixscan2, ixscan3]}}}; +let res = db.runCommand({stageDebug: {collection: collname, plan: andix1ix2}}); printjson(res); assert.eq(res.ok, 1); assert.eq(res.results.length, N); // Might as well make sure that hashed does the same thing. -andix1ix2hash = { - andHash: {args: {nodes: [ixscan1, ixscan2, ixscan3]}} -}; +let andix1ix2hash = {andHash: {args: {nodes: [ixscan1, ixscan2, ixscan3]}}}; res = db.runCommand({stageDebug: {collection: collname, plan: andix1ix2hash}}); assert.eq(res.ok, 1); assert.eq(res.results.length, N); diff --git a/jstests/core/stage_debug/stages_collection_scan.js b/jstests/core/stage_debug/stages_collection_scan.js index 08b3eb2eeb6..ce072ad68b4 100644 --- a/jstests/core/stage_debug/stages_collection_scan.js +++ b/jstests/core/stage_debug/stages_collection_scan.js @@ -8,7 +8,7 @@ // ] // Test basic query stage collection scan functionality. -t = db.stages_collection_scan; +let t = db.stages_collection_scan; t.drop(); var collname = "stages_collection_scan"; @@ -17,37 +17,29 @@ for (var i = 0; i < N; ++i) { t.insert({foo: i}); } -forward = { - cscan: {args: {direction: 1}} -}; -res = db.runCommand({stageDebug: {collection: collname, plan: forward}}); +let forward = {cscan: {args: {direction: 1}}}; +let res = db.runCommand({stageDebug: {collection: collname, plan: forward}}); assert.eq(res.ok, 1); assert.eq(res.results.length, N); assert.eq(res.results[0].foo, 0); assert.eq(res.results[49].foo, 49); // And, backwards. -backward = { - cscan: {args: {direction: -1}} -}; +let backward = {cscan: {args: {direction: -1}}}; res = db.runCommand({stageDebug: {collection: collname, plan: backward}}); assert.eq(res.ok, 1); assert.eq(res.results.length, N); assert.eq(res.results[0].foo, 49); assert.eq(res.results[49].foo, 0); -forwardFiltered = { - cscan: {args: {direction: 1}, filter: {foo: {$lt: 25}}} -}; +let forwardFiltered = {cscan: {args: {direction: 1}, filter: {foo: {$lt: 25}}}}; res = db.runCommand({stageDebug: {collection: collname, plan: forwardFiltered}}); assert.eq(res.ok, 1); assert.eq(res.results.length, 25); assert.eq(res.results[0].foo, 0); assert.eq(res.results[24].foo, 24); -backwardFiltered = { - cscan: {args: {direction: -1}, filter: {foo: {$lt: 25}}} -}; +let backwardFiltered = {cscan: {args: {direction: -1}, filter: {foo: {$lt: 25}}}}; res = db.runCommand({stageDebug: {collection: collname, plan: backwardFiltered}}); assert.eq(res.ok, 1); assert.eq(res.results.length, 25); diff --git a/jstests/core/stage_debug/stages_fetch.js b/jstests/core/stage_debug/stages_fetch.js index bdec393ce1c..30a7ef61ac6 100644 --- a/jstests/core/stage_debug/stages_fetch.js +++ b/jstests/core/stage_debug/stages_fetch.js @@ -7,7 +7,7 @@ // ] // Test basic fetch functionality. -t = db.stages_fetch; +let t = db.stages_fetch; t.drop(); var collname = "stages_fetch"; @@ -20,7 +20,7 @@ t.createIndex({foo: 1}); // 20 <= foo <= 30 // bar == 25 (not covered, should error.) -ixscan1 = { +let ixscan1 = { ixscan: { args: { keyPattern: {foo: 1}, @@ -33,11 +33,11 @@ ixscan1 = { filter: {bar: 25} } }; -res = db.runCommand({stageDebug: {collection: collname, plan: ixscan1}}); +let res = db.runCommand({stageDebug: {collection: collname, plan: ixscan1}}); assert.eq(res.ok, 0); // Now, add a fetch. We should be able to filter on the non-covered field since we fetched the obj. -ixscan2 = { +let ixscan2 = { ixscan: { args: { keyPattern: {foo: 1}, @@ -49,9 +49,7 @@ ixscan2 = { } } }; -fetch = { - fetch: {args: {node: ixscan2}, filter: {bar: 25}} -}; +let fetch = {fetch: {args: {node: ixscan2}, filter: {bar: 25}}}; res = db.runCommand({stageDebug: {collection: collname, plan: fetch}}); printjson(res); assert.eq(res.ok, 1); diff --git a/jstests/core/stage_debug/stages_ixscan.js b/jstests/core/stage_debug/stages_ixscan.js index de345fabb02..eb4d3c641d1 100644 --- a/jstests/core/stage_debug/stages_ixscan.js +++ b/jstests/core/stage_debug/stages_ixscan.js @@ -7,7 +7,7 @@ // ] // Test basic query stage index scan functionality. -t = db.stages_ixscan; +let t = db.stages_ixscan; t.drop(); var collname = "stages_ixscan"; @@ -40,7 +40,7 @@ assert.commandFailed(db.runCommand({ })); // foo <= 20 -ixscan1 = { +let ixscan1 = { ixscan: { args: { keyPattern: {foo: 1}, diff --git a/jstests/core/stage_debug/stages_limit_skip.js b/jstests/core/stage_debug/stages_limit_skip.js index 623e403c504..680ae9d682d 100644 --- a/jstests/core/stage_debug/stages_limit_skip.js +++ b/jstests/core/stage_debug/stages_limit_skip.js @@ -7,7 +7,7 @@ // ] // Test limit and skip -t = db.stages_limit_skip; +let t = db.stages_limit_skip; t.drop(); var collname = "stages_limit_skip"; @@ -20,7 +20,7 @@ t.createIndex({foo: 1}); // foo <= 20, decreasing // Limit of 5 results. -ixscan1 = { +let ixscan1 = { ixscan: { args: { keyPattern: {foo: 1}, @@ -32,10 +32,8 @@ ixscan1 = { } } }; -limit1 = { - limit: {args: {node: ixscan1, num: 5}} -}; -res = db.runCommand({stageDebug: {collection: collname, plan: limit1}}); +let limit1 = {limit: {args: {node: ixscan1, num: 5}}}; +let res = db.runCommand({stageDebug: {collection: collname, plan: limit1}}); assert.eq(res.ok, 1); assert.eq(res.results.length, 5); assert.eq(res.results[0].foo, 20); @@ -43,9 +41,7 @@ assert.eq(res.results[4].foo, 16); // foo <= 20, decreasing // Skip 5 results. -skip1 = { - skip: {args: {node: ixscan1, num: 5}} -}; +let skip1 = {skip: {args: {node: ixscan1, num: 5}}}; res = db.runCommand({stageDebug: {collection: collname, plan: skip1}}); assert.eq(res.ok, 1); assert.eq(res.results.length, 16); diff --git a/jstests/core/stage_debug/stages_mergesort.js b/jstests/core/stage_debug/stages_mergesort.js index c202a3ca827..b3203b98dac 100644 --- a/jstests/core/stage_debug/stages_mergesort.js +++ b/jstests/core/stage_debug/stages_mergesort.js @@ -7,7 +7,7 @@ // ] // Test query stage merge sorting. -t = db.stages_mergesort; +let t = db.stages_mergesort; t.drop(); var collname = "stages_mergesort"; @@ -22,7 +22,7 @@ t.createIndex({baz: 1, bar: 1}); // foo == 1 // We would (internally) use "": MinKey and "": MaxKey for the bar index bounds. -ixscan1 = { +let ixscan1 = { ixscan: { args: { keyPattern: {foo: 1, bar: 1}, @@ -35,7 +35,7 @@ ixscan1 = { } }; // baz == 1 -ixscan2 = { +let ixscan2 = { ixscan: { args: { keyPattern: {baz: 1, bar: 1}, @@ -48,10 +48,8 @@ ixscan2 = { } }; -mergesort = { - mergeSort: {args: {nodes: [ixscan1, ixscan2], pattern: {bar: 1}}} -}; -res = db.runCommand({stageDebug: {plan: mergesort, collection: collname}}); +let mergesort = {mergeSort: {args: {nodes: [ixscan1, ixscan2], pattern: {bar: 1}}}}; +let res = db.runCommand({stageDebug: {plan: mergesort, collection: collname}}); assert.eq(res.ok, 1); assert.eq(res.results.length, 2 * N); assert.eq(res.results[0].bar, 0); diff --git a/jstests/core/stage_debug/stages_or.js b/jstests/core/stage_debug/stages_or.js index 6eb2e9812fb..3c674c5f017 100644 --- a/jstests/core/stage_debug/stages_or.js +++ b/jstests/core/stage_debug/stages_or.js @@ -7,7 +7,7 @@ // ] // Test basic OR functionality -t = db.stages_or; +let t = db.stages_or; t.drop(); var collname = "stages_or"; @@ -21,7 +21,7 @@ t.createIndex({bar: 1}); t.createIndex({baz: 1}); // baz >= 40 -ixscan1 = { +let ixscan1 = { ixscan: { args: { keyPattern: {baz: 1}, @@ -34,7 +34,7 @@ ixscan1 = { } }; // foo >= 40 -ixscan2 = { +let ixscan2 = { ixscan: { args: { keyPattern: {foo: 1}, @@ -48,17 +48,13 @@ ixscan2 = { }; // OR of baz and foo. Baz == foo and we dedup. -orix1ix2 = { - or: {args: {nodes: [ixscan1, ixscan2], dedup: true}} -}; -res = db.runCommand({stageDebug: {collection: collname, plan: orix1ix2}}); +let orix1ix2 = {or: {args: {nodes: [ixscan1, ixscan2], dedup: true}}}; +let res = db.runCommand({stageDebug: {collection: collname, plan: orix1ix2}}); assert.eq(res.ok, 1); assert.eq(res.results.length, 10); // No deduping, 2x the results. -orix1ix2nodd = { - or: {args: {nodes: [ixscan1, ixscan2], dedup: false}} -}; +let orix1ix2nodd = {or: {args: {nodes: [ixscan1, ixscan2], dedup: false}}}; res = db.runCommand({stageDebug: {collection: collname, plan: orix1ix2nodd}}); assert.eq(res.ok, 1); assert.eq(res.results.length, 20); diff --git a/jstests/core/stage_debug/stages_sort.js b/jstests/core/stage_debug/stages_sort.js index 2fd682edc3c..a79b64bca0a 100644 --- a/jstests/core/stage_debug/stages_sort.js +++ b/jstests/core/stage_debug/stages_sort.js @@ -3,7 +3,7 @@ // @tags: [not_allowed_with_security_token] if (false) { - t = db.stages_sort; + let t = db.stages_sort; t.drop(); var N = 50; @@ -14,7 +14,7 @@ if (false) { t.createIndex({foo: 1}); // Foo <= 20, descending. - ixscan1 = { + let ixscan1 = { ixscan: { args: { name: "stages_sort", @@ -29,8 +29,8 @@ if (false) { }; // Sort with foo ascending. - sort1 = {sort: {args: {node: ixscan1, pattern: {foo: 1}}}}; - res = db.runCommand({stageDebug: sort1}); + let sort1 = {sort: {args: {node: ixscan1, pattern: {foo: 1}}}}; + let res = db.runCommand({stageDebug: sort1}); assert.eq(res.ok, 1); assert.eq(res.results.length, 21); assert.eq(res.results[0].foo, 0); diff --git a/jstests/core/string_with_nul_bytes.js b/jstests/core/string_with_nul_bytes.js index e72cc0b6dc1..718a1364666 100644 --- a/jstests/core/string_with_nul_bytes.js +++ b/jstests/core/string_with_nul_bytes.js @@ -1,9 +1,9 @@ // SERVER-6649 - issues round-tripping strings with embedded NUL bytes -t = db.string_with_nul_bytes.js; +let t = db.string_with_nul_bytes.js; t.drop(); -string = "string with a NUL (\0) byte"; +let string = "string with a NUL (\0) byte"; t.insert({str: string}); assert.eq(t.findOne().str, string); assert.eq(t.findOne().str.length, string.length); // just to be sure diff --git a/jstests/core/sub1.js b/jstests/core/sub1.js index d42677f3266..f38c5ccc4a0 100644 --- a/jstests/core/sub1.js +++ b/jstests/core/sub1.js @@ -1,16 +1,13 @@ // sub1.js -t = db.sub1; +let t = db.sub1; t.drop(); -x = { - a: 1, - b: {c: {d: 2}} -}; +let x = {a: 1, b: {c: {d: 2}}}; t.save(x); -y = t.findOne(); +let y = t.findOne(); assert.eq(1, y.a); assert.eq(2, y.b.c.d); diff --git a/jstests/core/testminmax.js b/jstests/core/testminmax.js index 3ebf0a13f3a..712b00f5151 100644 --- a/jstests/core/testminmax.js +++ b/jstests/core/testminmax.js @@ -1,6 +1,6 @@ // @tags: [requires_fastcount] -t = db.minmaxtest; +let t = db.minmaxtest; t.drop(); t.insert({ "_id": "IBM.N|00001264779918428889", diff --git a/jstests/core/timeseries/timeseries_groupby_reorder.js b/jstests/core/timeseries/timeseries_groupby_reorder.js index c4c34bc1249..a4f80197f10 100644 --- a/jstests/core/timeseries/timeseries_groupby_reorder.js +++ b/jstests/core/timeseries/timeseries_groupby_reorder.js @@ -26,7 +26,7 @@ assert.commandWorked(coll.insert({_id: 0, t: t, b: 2, c: 2})); assert.commandWorked(coll.insert({_id: 0, t: t, b: 3, c: 3})); // Test reordering the groupby and internal unpack buckets. -if (!isMongos(db)) { +if (!FixtureHelpers.isMongos(db)) { const res = coll.explain("queryPlanner").aggregate([ {$group: {_id: '$meta', accmin: {$min: '$b'}, accmax: {$max: '$c'}}} ]); diff --git a/jstests/core/timeseries/timeseries_update_one.js b/jstests/core/timeseries/timeseries_update_one.js index b53f645c5a0..2f9b45e9b83 100644 --- a/jstests/core/timeseries/timeseries_update_one.js +++ b/jstests/core/timeseries/timeseries_update_one.js @@ -248,7 +248,7 @@ function testUpdateOne({initialDocList, updateQuery, updateObj, resultDocList, n while (batchNum < 4) { let batch = []; for (let i = 0; i < 30; i++) { - const doc = {_id: i, [timeField]: ISODate(), value: "a".repeat(1000)}; + const doc = {_id: i, [timeFieldName]: ISODate(), value: "a".repeat(1000)}; batch.push(doc); } @@ -257,7 +257,7 @@ function testUpdateOne({initialDocList, updateQuery, updateObj, resultDocList, n } // Update any of the measurements with a document which will exceed the 128000 byte threshold. - const chunkyDoc = {_id: 128000, [timeField]: ISODate(), value: "a".repeat(10000)}; + const chunkyDoc = {_id: 128000, [timeFieldName]: ISODate(), value: "a".repeat(10000)}; testUpdateOne({ // initialDocList: We manually inserted measurements. updateQuery: {}, diff --git a/jstests/core/timeseries/timeseries_user_system_buckets.js b/jstests/core/timeseries/timeseries_user_system_buckets.js index 02ae0cb8f59..6835fca1864 100644 --- a/jstests/core/timeseries/timeseries_user_system_buckets.js +++ b/jstests/core/timeseries/timeseries_user_system_buckets.js @@ -13,8 +13,8 @@ * requires_fcv_63 * ] */ -userCollSystemBuckets = db.system.buckets.coll; -userColl = db.coll; +let userCollSystemBuckets = db.system.buckets.coll; +let userColl = db.coll; userCollSystemBuckets.drop(); userColl.drop(); @@ -25,10 +25,10 @@ assert.commandWorked(userCollSystemBuckets.insert({a: 1})); // A user collection with the same postfix should not be considered time series collection assert.commandWorked(userColl.insert({a: 2})); -docs = userColl.find().toArray(); +let docs = userColl.find().toArray(); assert.eq(1, docs.length); -docsSystemBuckets = userCollSystemBuckets.find().toArray(); +let docsSystemBuckets = userCollSystemBuckets.find().toArray(); assert.eq(1, docsSystemBuckets.length); userCollSystemBuckets.drop(); diff --git a/jstests/core/txns/commands_banning_txnnumber_outside_transactions.js b/jstests/core/txns/commands_banning_txnnumber_outside_transactions.js index a32cc59e255..49f03c6fddc 100644 --- a/jstests/core/txns/commands_banning_txnnumber_outside_transactions.js +++ b/jstests/core/txns/commands_banning_txnnumber_outside_transactions.js @@ -11,7 +11,7 @@ (function() { "use strict"; -const isMongos = assert.commandWorked(db.runCommand("hello")).msg === "isdbgrid"; +load("jstests/libs/fixture_helpers.js"); const session = db.getMongo().startSession(); const sessionDb = session.getDatabase("admin"); @@ -53,7 +53,7 @@ nonRetryableWriteCommands.forEach(function(command) { [50768, 50889]); }); -if (!isMongos) { +if (!FixtureHelpers.isMongos(db)) { nonRetryableWriteCommandsMongodOnly.forEach(function(command) { jsTest.log("Testing command: " + tojson(command)); assert.commandFailedWithCode( diff --git a/jstests/core/txns/commands_not_allowed_in_txn.js b/jstests/core/txns/commands_not_allowed_in_txn.js index a261b14a0be..45352c27109 100644 --- a/jstests/core/txns/commands_not_allowed_in_txn.js +++ b/jstests/core/txns/commands_not_allowed_in_txn.js @@ -29,7 +29,7 @@ const sessionOptions = { const session = db.getMongo().startSession(sessionOptions); const sessionDb = session.getDatabase(dbName); -const isMongos = assert.commandWorked(db.runCommand("hello")).msg === "isdbgrid"; +const runningOnMongos = assert.commandWorked(db.runCommand("hello")).msg === "isdbgrid"; assert.commandWorked(testDB.createCollection(testColl.getName(), {writeConcern: {w: "majority"}})); assert.commandWorked(testDB.runCommand({ @@ -69,7 +69,7 @@ function testCommand(command) { assert(res.errmsg.match(errmsgRegExp), res); // Mongos has special handling for commitTransaction to support commit recovery. - if (!isMongos) { + if (!runningOnMongos) { assert.commandFailedWithCode(sessionDb.adminCommand({ commitTransaction: 1, txnNumber: NumberLong(txnNumber), @@ -134,7 +134,7 @@ const commands = [ ]; // There is no applyOps command on mongos. -if (!isMongos) { +if (!runningOnMongos) { commands.push({ applyOps: [{ op: "u", @@ -164,7 +164,7 @@ assert.commandFailedWithCode(sessionDb.runCommand({ ErrorCodes.OperationNotSupportedInTransaction); // Mongos has special handling for commitTransaction to support commit recovery. -if (!isMongos) { +if (!runningOnMongos) { // The failed find should abort the transaction so a commit should fail. assert.commandFailedWithCode(sessionDb.adminCommand({ commitTransaction: 1, diff --git a/jstests/core/txns/dbstats_not_blocked_by_txn.js b/jstests/core/txns/dbstats_not_blocked_by_txn.js index 6555a216e14..3eaec86df82 100644 --- a/jstests/core/txns/dbstats_not_blocked_by_txn.js +++ b/jstests/core/txns/dbstats_not_blocked_by_txn.js @@ -7,6 +7,8 @@ */ (function() { "use strict"; +load("jstests/libs/fixture_helpers.js"); + var dbName = 'dbstats_not_blocked_by_txn'; var mydb = db.getSiblingDB(dbName); @@ -16,8 +18,7 @@ mydb.createCollection("foo", {writeConcern: {w: "majority"}}); var session = db.getMongo().startSession(); var sessionDb = session.getDatabase(dbName); -const isMongos = assert.commandWorked(db.runCommand("hello")).msg === "isdbgrid"; -if (isMongos) { +if (FixtureHelpers.isMongos(db)) { // Before starting the transaction below, access the collection so it can be implicitly // sharded and force all shards to refresh their database versions because the refresh // requires an exclusive lock and would block behind the transaction. diff --git a/jstests/core/txns/list_collections_not_blocked_by_txn.js b/jstests/core/txns/list_collections_not_blocked_by_txn.js index 1ef9bb17b38..7b615c076f8 100644 --- a/jstests/core/txns/list_collections_not_blocked_by_txn.js +++ b/jstests/core/txns/list_collections_not_blocked_by_txn.js @@ -9,6 +9,7 @@ // TODO (SERVER-39704): Remove the following load after SERVER-397074 is completed // For withTxnAndAutoRetryOnMongos. load('jstests/libs/auto_retry_transaction_in_sharding.js'); +load("jstests/libs/fixture_helpers.js"); var dbName = 'list_collections_not_blocked'; var mydb = db.getSiblingDB(dbName); @@ -19,8 +20,7 @@ mydb.foo.drop({writeConcern: {w: "majority"}}); assert.commandWorked(mydb.createCollection("foo", {writeConcern: {w: "majority"}})); -const isMongos = assert.commandWorked(db.runCommand("hello")).msg === "isdbgrid"; -if (isMongos) { +if (FixtureHelpers.isMongos(db)) { // Before starting the transaction below, access the collection so it can be implicitly // sharded and force all shards to refresh their database versions because the refresh // requires an exclusive lock and would block behind the transaction. diff --git a/jstests/core/txns/noop_createIndexes_not_blocked_by_txn.js b/jstests/core/txns/noop_createIndexes_not_blocked_by_txn.js index 75310ac65d2..083a2b978cd 100644 --- a/jstests/core/txns/noop_createIndexes_not_blocked_by_txn.js +++ b/jstests/core/txns/noop_createIndexes_not_blocked_by_txn.js @@ -6,6 +6,7 @@ // TODO(SERVER-39704): Remove the following load after SERVER-39704 is completed // For withTxnAndAutoRetryOnMongos. load('jstests/libs/auto_retry_transaction_in_sharding.js'); +load("jstests/libs/fixture_helpers.js"); const dbName = 'noop_createIndexes_not_blocked'; const collName = 'test'; @@ -16,8 +17,7 @@ testDB.runCommand({drop: collName, writeConcern: {w: "majority"}}); const session = db.getMongo().startSession({causalConsistency: false}); const sessionDB = session.getDatabase(dbName); -const isMongos = assert.commandWorked(db.runCommand("hello")).msg === "isdbgrid"; -if (isMongos) { +if (FixtureHelpers.isMongos(db)) { // Access the collection before creating indexes so it can be implicitly sharded. assert.eq(sessionDB[collName].find().itcount(), 0); } diff --git a/jstests/core/txns/statement_ids_accepted.js b/jstests/core/txns/statement_ids_accepted.js index b5a56b31870..14e64897cf2 100644 --- a/jstests/core/txns/statement_ids_accepted.js +++ b/jstests/core/txns/statement_ids_accepted.js @@ -8,6 +8,7 @@ // # Tenant migrations don't support applyOps. // tenant_migration_incompatible // ] +load("jstests/libs/fixture_helpers.js"); (function() { "use strict"; @@ -172,8 +173,7 @@ assert.commandWorked(sessionDb.adminCommand({ autocommit: false })); -const isMongos = assert.commandWorked(db.runCommand("hello")).msg === "isdbgrid"; -if (!isMongos) { +if (!FixtureHelpers.isMongos(db)) { // Skip commands that do not exist on mongos. jsTestLog("Check that prepareTransaction accepts a statement ID"); diff --git a/jstests/core/views/invalid_system_views.js b/jstests/core/views/invalid_system_views.js index 8c90068c81e..1844046056b 100644 --- a/jstests/core/views/invalid_system_views.js +++ b/jstests/core/views/invalid_system_views.js @@ -18,11 +18,12 @@ * uses_compact, * ] */ +load("jstests/libs/fixture_helpers.js"); (function() { "use strict"; -const isMongos = db.runCommand({isdbgrid: 1}).isdbgrid; -const isStandalone = !isMongos && !db.runCommand({hello: 1}).hasOwnProperty("setName"); +const runningOnMongos = FixtureHelpers.isMongos(db); +const isStandalone = !runningOnMongos && !db.runCommand({hello: 1}).hasOwnProperty("setName"); function runTest(badViewDefinition) { let viewsDB = db.getSiblingDB("invalid_system_views"); @@ -52,7 +53,7 @@ function runTest(badViewDefinition) { " in system.views"; } - if (!isMongos) { + if (!runningOnMongos) { // Commands that run on existing regular collections should not be impacted by the // presence of invalid views. However, applyOps doesn't work on mongos. assert.commandWorked( @@ -107,7 +108,7 @@ function runTest(badViewDefinition) { } const storageEngine = jsTest.options().storageEngine; - if (isMongos || storageEngine === "inMemory") { + if (runningOnMongos || storageEngine === "inMemory") { print("Not testing compact command on mongos or ephemeral storage engine"); } else { assert.commandWorked(viewsDB.runCommand({compact: "collection", force: true}), diff --git a/jstests/core/views/views_stats.js b/jstests/core/views/views_stats.js index 3bda9eec250..623ef6b4dfd 100644 --- a/jstests/core/views/views_stats.js +++ b/jstests/core/views/views_stats.js @@ -17,6 +17,7 @@ (function() { "use strict"; load("jstests/libs/stats.js"); +load("jstests/libs/fixture_helpers.js"); let viewsDB = db.getSiblingDB("views_stats"); assert.commandWorked(viewsDB.dropDatabase()); @@ -42,9 +43,7 @@ lastHistogram = assertHistogramDiffEq(view, lastHistogram, 0, 1, 0); assert.writeError(view.update({}, {})); lastHistogram = assertHistogramDiffEq(view, lastHistogram, 0, 1, 0); -let helloResponse = assert.commandWorked(viewsDB.runCommand("hello")); -const isMongos = (helloResponse.msg === "isdbgrid"); -if (isMongos) { +if (FixtureHelpers.isMongos(viewsDB)) { jsTest.log("Tests are being run on a mongos; skipping top tests."); return; } diff --git a/jstests/core/write/autoid.js b/jstests/core/write/autoid.js index 679b109fcc5..1797e3d7baf 100644 --- a/jstests/core/write/autoid.js +++ b/jstests/core/write/autoid.js @@ -3,14 +3,14 @@ // key. // @tags: [assumes_unsharded_collection] -f = db.jstests_autoid; +let f = db.jstests_autoid; f.drop(); f.save({z: 1}); -a = f.findOne({z: 1}); +let a = f.findOne({z: 1}); f.update({z: 1}, {z: 2}); -b = f.findOne({z: 2}); +let b = f.findOne({z: 2}); assert.eq(a._id.str, b._id.str); -c = f.update({z: 2}, {z: "abcdefgabcdefgabcdefg"}); +let c = f.update({z: 2}, {z: "abcdefgabcdefgabcdefg"}); c = f.findOne({}); assert.eq(a._id.str, c._id.str); diff --git a/jstests/core/write/batch_write_command_w0.js b/jstests/core/write/batch_write_command_w0.js index 7d5038120b6..4b6bcb02168 100644 --- a/jstests/core/write/batch_write_command_w0.js +++ b/jstests/core/write/batch_write_command_w0.js @@ -33,12 +33,8 @@ coll.drop(); // // Single document insert, w:0 write concern specified, missing ordered coll.drop(); -request = { - insert: coll.getName(), - documents: [{a: 1}], - writeConcern: {w: 0} -}; -result = coll.runCommand(request); +let request = {insert: coll.getName(), documents: [{a: 1}], writeConcern: {w: 0}}; +let result = coll.runCommand(request); assert.eq({ok: 1}, result); countEventually(coll, 1); diff --git a/jstests/core/write/delete/remove.js b/jstests/core/write/delete/remove.js index f08792aeca5..e3ecd634321 100644 --- a/jstests/core/write/delete/remove.js +++ b/jstests/core/write/delete/remove.js @@ -3,11 +3,11 @@ // remove.js // unit test for db remove -t = db.removetest; +let t = db.removetest; function f(n, dir) { t.createIndex({x: dir || 1}); - for (i = 0; i < n; i++) + for (let i = 0; i < n; i++) t.save({x: 3, z: "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"}); assert.eq(n, t.find().count()); diff --git a/jstests/core/write/delete/remove3.js b/jstests/core/write/delete/remove3.js index 6f0a94589e9..c2ce5ffead8 100644 --- a/jstests/core/write/delete/remove3.js +++ b/jstests/core/write/delete/remove3.js @@ -1,9 +1,9 @@ // @tags: [requires_non_retryable_writes, requires_fastcount] -t = db.remove3; +let t = db.remove3; t.drop(); -for (i = 1; i <= 8; i++) { +for (let i = 1; i <= 8; i++) { t.save({_id: i, x: i}); } diff --git a/jstests/core/write/delete/remove4.js b/jstests/core/write/delete/remove4.js index 483de24bf7d..43dcbc5807b 100644 --- a/jstests/core/write/delete/remove4.js +++ b/jstests/core/write/delete/remove4.js @@ -1,6 +1,6 @@ // @tags: [requires_non_retryable_writes] -t = db.remove4; +let t = db.remove4; t.drop(); t.save({a: 1, b: 1}); diff --git a/jstests/core/write/delete/remove6.js b/jstests/core/write/delete/remove6.js index f60200a8d81..0546fa3f8b6 100644 --- a/jstests/core/write/delete/remove6.js +++ b/jstests/core/write/delete/remove6.js @@ -1,9 +1,9 @@ // @tags: [requires_non_retryable_writes, requires_fastcount] -t = db.remove6; +let t = db.remove6; t.drop(); -N = 1000; +let N = 1000; function pop() { t.drop(); diff --git a/jstests/core/write/delete/remove7.js b/jstests/core/write/delete/remove7.js index 9cc86329990..9924a34362c 100644 --- a/jstests/core/write/delete/remove7.js +++ b/jstests/core/write/delete/remove7.js @@ -1,6 +1,6 @@ // @tags: [requires_non_retryable_writes] -t = db.remove7; +let t = db.remove7; t.drop(); function getTags(n) { @@ -14,13 +14,13 @@ function getTags(n) { return a; } -for (i = 0; i < 1000; i++) { +for (let i = 0; i < 1000; i++) { t.save({tags: getTags()}); } t.createIndex({tags: 1}); -for (i = 0; i < 200; i++) { +for (let i = 0; i < 200; i++) { for (var j = 0; j < 10; j++) t.save({tags: getTags(100)}); var q = {tags: {$in: getTags(10)}}; diff --git a/jstests/core/write/delete/remove8.js b/jstests/core/write/delete/remove8.js index 7a8263c21e4..3f34a753e92 100644 --- a/jstests/core/write/delete/remove8.js +++ b/jstests/core/write/delete/remove8.js @@ -4,10 +4,10 @@ // requires_fastcount, // ] -t = db.remove8; +let t = db.remove8; t.drop(); -N = 1000; +let N = 1000; function fill() { for (var i = 0; i < N; i++) { diff --git a/jstests/core/write/delete/remove_justone.js b/jstests/core/write/delete/remove_justone.js index f5345627e34..1ae630432db 100644 --- a/jstests/core/write/delete/remove_justone.js +++ b/jstests/core/write/delete/remove_justone.js @@ -3,7 +3,7 @@ // key. // @tags: [assumes_unsharded_collection, requires_non_retryable_writes, requires_fastcount] -t = db.remove_justone; +let t = db.remove_justone; t.drop(); t.insert({x: 1}); diff --git a/jstests/core/write/delete/removec.js b/jstests/core/write/delete/removec.js index 560f7405de3..bd68d43201c 100644 --- a/jstests/core/write/delete/removec.js +++ b/jstests/core/write/delete/removec.js @@ -6,36 +6,36 @@ // Sanity test for removing documents with adjacent index keys. SERVER-2008 -t = db.jstests_removec; +let t = db.jstests_removec; t.drop(); t.createIndex({a: 1}); /** @return an array containing a sequence of numbers from i to i + 10. */ function runStartingWith(i) { - ret = []; - for (j = 0; j < 11; ++j) { + let ret = []; + for (let j = 0; j < 11; ++j) { ret.push(i + j); } return ret; } // Insert some documents with adjacent index keys. -for (i = 0; i < 1100; i += 11) { +for (let i = 0; i < 1100; i += 11) { t.save({a: runStartingWith(i)}); } // Remove and then reinsert random documents in the background. -s = startParallelShell('t = db.jstests_removec;' + - 'Random.setRandomSeed();' + - 'for( j = 0; j < 1000; ++j ) {' + - ' o = t.findOne( { a:Random.randInt( 1100 ) } );' + - ' t.remove( { _id:o._id } );' + - ' t.insert( o );' + - '}'); +let s = startParallelShell('t = db.jstests_removec;' + + 'Random.setRandomSeed();' + + 'for( j = 0; j < 1000; ++j ) {' + + ' o = t.findOne( { a:Random.randInt( 1100 ) } );' + + ' t.remove( { _id:o._id } );' + + ' t.insert( o );' + + '}'); // Find operations are error free. Note that the cursor throws if it detects the $err // field in the returned document. -for (i = 0; i < 200; ++i) { +for (let i = 0; i < 200; ++i) { t.find({a: {$gte: 0}}).hint({a: 1}).itcount(); } diff --git a/jstests/core/write/find_and_modify/find_and_modify.js b/jstests/core/write/find_and_modify/find_and_modify.js index 56eae294568..47885cf9c92 100644 --- a/jstests/core/write/find_and_modify/find_and_modify.js +++ b/jstests/core/write/find_and_modify/find_and_modify.js @@ -6,7 +6,7 @@ // requires_fastcount, // ] -t = db.find_and_modify; +let t = db.find_and_modify; t.drop(); // fill db @@ -15,7 +15,8 @@ for (var i = 1; i <= 10; i++) { } // returns old -out = t.findAndModify({sort: {priority: 1}, update: {$set: {inprogress: true}, $inc: {value: 1}}}); +let out = + t.findAndModify({sort: {priority: 1}, update: {$set: {inprogress: true}, $inc: {value: 1}}}); assert.eq(out.value, 0); assert.eq(out.inprogress, false); t.update({_id: out._id}, {$set: {inprogress: false}}); @@ -133,7 +134,7 @@ runFindAndModify(true /* shouldMatch */, false /* upsert */, false /* new */); // t.drop(); -cmdRes = db.runCommand( +let cmdRes = db.runCommand( {findAndModify: t.getName(), query: {_id: "miss"}, update: {$inc: {y: 1}}, upsert: true}); assert.commandWorked(cmdRes); assert("value" in cmdRes); diff --git a/jstests/core/write/find_and_modify/find_and_modify3.js b/jstests/core/write/find_and_modify/find_and_modify3.js index a319aef7a2d..8aee710a0cf 100644 --- a/jstests/core/write/find_and_modify/find_and_modify3.js +++ b/jstests/core/write/find_and_modify/find_and_modify3.js @@ -3,7 +3,7 @@ // key. // @tags: [assumes_unsharded_collection] -t = db.find_and_modify3; +let t = db.find_and_modify3; t.drop(); t.insert({_id: 0, other: 0, comments: [{i: 0, j: 0}, {i: 1, j: 1}]}); @@ -14,10 +14,10 @@ t.insert({ }); // this is the only one that gets modded t.insert({_id: 2, other: 2, comments: [{i: 0, j: 0}, {i: 1, j: 1}]}); -orig0 = t.findOne({_id: 0}); -orig2 = t.findOne({_id: 2}); +let orig0 = t.findOne({_id: 0}); +let orig2 = t.findOne({_id: 2}); -out = t.findAndModify({ +let out = t.findAndModify({ query: {_id: 1, 'comments.i': 0}, update: {$set: {'comments.$.j': 2}}, 'new': true, diff --git a/jstests/core/write/find_and_modify/find_and_modify4.js b/jstests/core/write/find_and_modify/find_and_modify4.js index d5b3ae23cb2..8d23edb62a9 100644 --- a/jstests/core/write/find_and_modify/find_and_modify4.js +++ b/jstests/core/write/find_and_modify/find_and_modify4.js @@ -3,7 +3,7 @@ // key. // @tags: [assumes_unsharded_collection, requires_fastcount] -t = db.find_and_modify4; +let t = db.find_and_modify4; t.drop(); // this is the best way to build auto-increment diff --git a/jstests/core/write/find_and_modify/find_and_modify_server6254.js b/jstests/core/write/find_and_modify/find_and_modify_server6254.js index 5a0dae9db22..2cb527446ba 100644 --- a/jstests/core/write/find_and_modify/find_and_modify_server6254.js +++ b/jstests/core/write/find_and_modify/find_and_modify_server6254.js @@ -3,11 +3,11 @@ // key. // @tags: [assumes_unsharded_collection, requires_fastcount] -t = db.find_and_modify_server6254; +let t = db.find_and_modify_server6254; t.drop(); t.insert({x: 1}); -ret = t.findAndModify({query: {x: 1}, update: {$set: {x: 2}}, new: true}); +let ret = t.findAndModify({query: {x: 1}, update: {$set: {x: 2}}, new: true}); assert.eq(2, ret.x, tojson(ret)); assert.eq(1, t.count()); diff --git a/jstests/core/write/find_and_modify/find_and_modify_server6582.js b/jstests/core/write/find_and_modify/find_and_modify_server6582.js index 7ad8aebee76..2e5b38af2a2 100644 --- a/jstests/core/write/find_and_modify/find_and_modify_server6582.js +++ b/jstests/core/write/find_and_modify/find_and_modify_server6582.js @@ -3,11 +3,12 @@ // key. // @tags: [assumes_unsharded_collection] -t = db.find_and_modify_server6582; +let t = db.find_and_modify_server6582; t.drop(); -x = t.runCommand("findAndModify", {query: {f: 1}, update: {$set: {f: 2}}, upsert: true, new: true}); -le = x.lastErrorObject; +let x = + t.runCommand("findAndModify", {query: {f: 1}, update: {$set: {f: 2}}, upsert: true, new: true}); +let le = x.lastErrorObject; assert.eq(le.updatedExisting, false); assert.eq(le.n, 1); assert.eq(le.upserted, x.value._id); diff --git a/jstests/core/write/find_and_modify/find_and_modify_server6588.js b/jstests/core/write/find_and_modify/find_and_modify_server6588.js index 197c892ca67..344bb74a241 100644 --- a/jstests/core/write/find_and_modify/find_and_modify_server6588.js +++ b/jstests/core/write/find_and_modify/find_and_modify_server6588.js @@ -3,25 +3,12 @@ // key. // @tags: [assumes_unsharded_collection] -t = db.find_and_modify_sever6588; +let t = db.find_and_modify_sever6588; -initial = { - _id: 1, - a: [{b: 1}], - z: 1 -}; -up = { - "$set": {"a.$.b": 2} -}; -q = { - _id: 1, - "a.b": 1 -}; -correct = { - _id: 1, - a: [{b: 2}], - z: 1 -}; +let initial = {_id: 1, a: [{b: 1}], z: 1}; +let up = {"$set": {"a.$.b": 2}}; +let q = {_id: 1, "a.b": 1}; +let correct = {_id: 1, a: [{b: 2}], z: 1}; t.drop(); t.insert(initial); @@ -30,7 +17,7 @@ assert.eq(correct, t.findOne()); t.drop(); t.insert(initial); -x = t.findAndModify({query: q, update: up}); +let x = t.findAndModify({query: q, update: up}); assert.eq(correct, t.findOne()); t.drop(); diff --git a/jstests/core/write/find_and_modify/find_and_modify_server6659.js b/jstests/core/write/find_and_modify/find_and_modify_server6659.js index 029a32d6a49..091c9e93ebc 100644 --- a/jstests/core/write/find_and_modify/find_and_modify_server6659.js +++ b/jstests/core/write/find_and_modify/find_and_modify_server6659.js @@ -3,9 +3,9 @@ // key. // @tags: [assumes_unsharded_collection] -t = db.find_and_modify_server6659; +let t = db.find_and_modify_server6659; t.drop(); -x = t.findAndModify({query: {f: 1}, update: {$set: {f: 2}}, upsert: true, new: true}); +let x = t.findAndModify({query: {f: 1}, update: {$set: {f: 2}}, upsert: true, new: true}); assert.eq(2, x.f); assert.eq(2, t.findOne().f); diff --git a/jstests/core/write/find_and_modify/find_and_modify_server6909.js b/jstests/core/write/find_and_modify/find_and_modify_server6909.js index c74e342822b..24a62a9ba2b 100644 --- a/jstests/core/write/find_and_modify/find_and_modify_server6909.js +++ b/jstests/core/write/find_and_modify/find_and_modify_server6909.js @@ -3,12 +3,12 @@ // key. // @tags: [assumes_unsharded_collection] -c = db.find_and_modify_server6906; +let c = db.find_and_modify_server6906; c.drop(); c.insert({_id: 5, a: {b: 1}}); -ret = c.findAndModify({ +let ret = c.findAndModify({ query: {'a.b': 1}, update: {$set: {'a.b': 2}}, // Ensure the query on 'a.b' no longer matches. new: true diff --git a/jstests/core/write/find_and_modify/find_and_modify_server6993.js b/jstests/core/write/find_and_modify/find_and_modify_server6993.js index 4d9b169700d..eec75a9679b 100644 --- a/jstests/core/write/find_and_modify/find_and_modify_server6993.js +++ b/jstests/core/write/find_and_modify/find_and_modify_server6993.js @@ -3,7 +3,7 @@ // key. // @tags: [assumes_unsharded_collection] -c = db.find_and_modify_server6993; +let c = db.find_and_modify_server6993; c.drop(); c.insert({a: [1, 2]}); diff --git a/jstests/core/write/find_and_modify/find_and_modify_server7660.js b/jstests/core/write/find_and_modify/find_and_modify_server7660.js index 7973279ddcf..3ec3d715405 100644 --- a/jstests/core/write/find_and_modify/find_and_modify_server7660.js +++ b/jstests/core/write/find_and_modify/find_and_modify_server7660.js @@ -3,13 +3,13 @@ // key. // @tags: [assumes_unsharded_collection] -t = db.find_and_modify_server7660; +let t = db.find_and_modify_server7660; t.drop(); -a = t.findAndModify( +let a = t.findAndModify( {query: {foo: 'bar'}, update: {$set: {bob: 'john'}}, sort: {foo: 1}, upsert: true, new: true}); -b = t.findOne(); +let b = t.findOne(); assert.eq(a, b); assert.eq("bar", a.foo); assert.eq("john", a.bob); diff --git a/jstests/core/write/find_and_modify/find_and_modify_where.js b/jstests/core/write/find_and_modify/find_and_modify_where.js index 62375da7aab..6d605f9d23a 100644 --- a/jstests/core/write/find_and_modify/find_and_modify_where.js +++ b/jstests/core/write/find_and_modify/find_and_modify_where.js @@ -8,11 +8,11 @@ // requires_scripting, // ] -t = db.find_and_modify_where; +let t = db.find_and_modify_where; t.drop(); t.insert({_id: 1, x: 1}); -res = t.findAndModify({query: {$where: "return this.x == 1"}, update: {$set: {y: 1}}}); +let res = t.findAndModify({query: {$where: "return this.x == 1"}, update: {$set: {y: 1}}}); assert.eq(1, t.findOne().y); diff --git a/jstests/core/write/insert/insert_id_undefined.js b/jstests/core/write/insert/insert_id_undefined.js index 6d0bc38f8fb..80873def9c6 100644 --- a/jstests/core/write/insert/insert_id_undefined.js +++ b/jstests/core/write/insert/insert_id_undefined.js @@ -3,7 +3,7 @@ // @tags: [assumes_no_implicit_collection_creation_after_drop, requires_fastcount] // ensure a document with _id undefined cannot be saved -t = db.insert_id_undefined; +let t = db.insert_id_undefined; t.drop(); t.insert({_id: undefined}); assert.eq(t.count(), 0); diff --git a/jstests/core/write/update/update2.js b/jstests/core/write/update/update2.js index 080875b50bd..a026346e355 100644 --- a/jstests/core/write/update/update2.js +++ b/jstests/core/write/update/update2.js @@ -3,7 +3,7 @@ // key. // @tags: [assumes_unsharded_collection] -f = db.ed_db_update2; +let f = db.ed_db_update2; f.drop(); f.save({a: 4}); diff --git a/jstests/core/write/update/update3.js b/jstests/core/write/update/update3.js index 7e6c233e27a..884a65e9e0e 100644 --- a/jstests/core/write/update/update3.js +++ b/jstests/core/write/update/update3.js @@ -5,7 +5,7 @@ // Update with mods corner cases. -f = db.jstests_update3; +let f = db.jstests_update3; f.drop(); f.save({a: 1}); diff --git a/jstests/core/write/update/update5.js b/jstests/core/write/update/update5.js index fafc0d72ce0..2bdcaea1ef2 100644 --- a/jstests/core/write/update/update5.js +++ b/jstests/core/write/update/update5.js @@ -4,7 +4,7 @@ // // @tags: [assumes_unsharded_collection, requires_fastcount] -t = db.update5; +let t = db.update5; function go(key) { t.drop(); @@ -24,7 +24,7 @@ function go(key) { check(3, "C"); var ik = {}; - for (k in key) + for (let k in key) ik[k] = 1; t.createIndex(ik); diff --git a/jstests/core/write/update/update6.js b/jstests/core/write/update/update6.js index 8a1950b8d02..7704e921151 100644 --- a/jstests/core/write/update/update6.js +++ b/jstests/core/write/update/update6.js @@ -5,7 +5,7 @@ // assumes_unsharded_collection, // ] -t = db.update6; +let t = db.update6; t.drop(); t.save({a: 1, b: {c: 1, d: 1}}); diff --git a/jstests/core/write/update/update7.js b/jstests/core/write/update/update7.js index d3a7a5d1deb..a7fcbbfddf0 100644 --- a/jstests/core/write/update/update7.js +++ b/jstests/core/write/update/update7.js @@ -3,7 +3,7 @@ // key. // @tags: [assumes_unsharded_collection, requires_multi_updates, requires_non_retryable_writes] -t = db.update7; +let t = db.update7; t.drop(); function s() { @@ -119,6 +119,7 @@ assert.eq("4,7,", s(), "E1"); t.update({}, {$inc: {x: 1}}, false, true); assert.eq("5,8,1", s(), "E2"); +let i; for (i = 4; i < 8; i++) t.save({_id: i}); t.save({_id: i, x: 1}); diff --git a/jstests/core/write/update/update8.js b/jstests/core/write/update/update8.js index 596bc8695dd..7db54242cf3 100644 --- a/jstests/core/write/update/update8.js +++ b/jstests/core/write/update/update8.js @@ -1,5 +1,5 @@ -t = db.update8; +let t = db.update8; t.drop(); t.update({_id: 1, tags: {"$ne": "a"}}, {"$push": {tags: "a"}}, true); diff --git a/jstests/core/write/update/update9.js b/jstests/core/write/update/update9.js index d119681a09e..e7f9da8ddb6 100644 --- a/jstests/core/write/update/update9.js +++ b/jstests/core/write/update/update9.js @@ -1,8 +1,8 @@ -t = db.update9; +let t = db.update9; t.drop(); -orig = { +let orig = { "_id": 1, "question": "a", "choices": {"1": {"choice": "b"}, "0": {"choice": "c"}}, diff --git a/jstests/core/write/update/update_addToSet2.js b/jstests/core/write/update/update_addToSet2.js index 44ba8bce671..2aabdb3078c 100644 --- a/jstests/core/write/update/update_addToSet2.js +++ b/jstests/core/write/update/update_addToSet2.js @@ -1,10 +1,8 @@ -t = db.update_addToSet2; +let t = db.update_addToSet2; t.drop(); -o = { - _id: 1 -}; +let o = {_id: 1}; t.insert({_id: 1}); t.update({}, {$addToSet: {'kids': {'name': 'Bob', 'age': '4'}}}); diff --git a/jstests/core/write/update/update_addToSet3.js b/jstests/core/write/update/update_addToSet3.js index efd682cef4c..ee13b651233 100644 --- a/jstests/core/write/update/update_addToSet3.js +++ b/jstests/core/write/update/update_addToSet3.js @@ -1,6 +1,6 @@ // Test the use of $each in $addToSet -t = db.update_addToSet3; +let t = db.update_addToSet3; t.drop(); t.insert({_id: 1}); diff --git a/jstests/core/write/update/update_arraymatch1.js b/jstests/core/write/update/update_arraymatch1.js index 10b7e37e451..dd88af731aa 100644 --- a/jstests/core/write/update/update_arraymatch1.js +++ b/jstests/core/write/update/update_arraymatch1.js @@ -3,19 +3,14 @@ // key. // @tags: [assumes_unsharded_collection] -t = db.update_arraymatch1; +let t = db.update_arraymatch1; t.drop(); -o = { - _id: 1, - a: [{x: 1, y: 1}, {x: 2, y: 2}, {x: 3, y: 3}] -}; +let o = {_id: 1, a: [{x: 1, y: 1}, {x: 2, y: 2}, {x: 3, y: 3}]}; t.insert(o); assert.eq(o, t.findOne(), "A1"); -q = { - "a.x": 2 -}; +let q = {"a.x": 2}; t.update(q, {$set: {b: 5}}); o.b = 5; assert.eq(o, t.findOne(), "A2"); diff --git a/jstests/core/write/update/update_arraymatch2.js b/jstests/core/write/update/update_arraymatch2.js index 7610de7c962..5ec6be9e3cf 100644 --- a/jstests/core/write/update/update_arraymatch2.js +++ b/jstests/core/write/update/update_arraymatch2.js @@ -1,6 +1,6 @@ // @tags: [requires_multi_updates, requires_non_retryable_writes] -t = db.update_arraymatch2; +let t = db.update_arraymatch2; t.drop(); t.insert({}); diff --git a/jstests/core/write/update/update_arraymatch3.js b/jstests/core/write/update/update_arraymatch3.js index 36f7ab22430..e16a518fd80 100644 --- a/jstests/core/write/update/update_arraymatch3.js +++ b/jstests/core/write/update/update_arraymatch3.js @@ -1,13 +1,9 @@ // @tags: [requires_multi_updates, requires_non_retryable_writes] -t = db.update_arraymatch3; +let t = db.update_arraymatch3; t.drop(); -o = { - _id: 1, - title: "ABC", - comments: [{"by": "joe", "votes": 3}, {"by": "jane", "votes": 7}] -}; +let o = {_id: 1, title: "ABC", comments: [{"by": "joe", "votes": 3}, {"by": "jane", "votes": 7}]}; t.save(o); assert.eq(o, t.findOne(), "A1"); diff --git a/jstests/core/write/update/update_arraymatch4.js b/jstests/core/write/update/update_arraymatch4.js index 3c087e53ca5..6c8f378fad1 100644 --- a/jstests/core/write/update/update_arraymatch4.js +++ b/jstests/core/write/update/update_arraymatch4.js @@ -3,13 +3,10 @@ // key. // @tags: [assumes_unsharded_collection] -t = db.update_arraymatch4; +let t = db.update_arraymatch4; t.drop(); -x = { - _id: 1, - arr: ["A1", "B1", "C1"] -}; +let x = {_id: 1, arr: ["A1", "B1", "C1"]}; t.insert(x); assert.eq(x, t.findOne(), "A1"); diff --git a/jstests/core/write/update/update_arraymatch5.js b/jstests/core/write/update/update_arraymatch5.js index 1b4c967b38b..0d676f3e4e5 100644 --- a/jstests/core/write/update/update_arraymatch5.js +++ b/jstests/core/write/update/update_arraymatch5.js @@ -4,7 +4,7 @@ // requires_non_retryable_writes, // ] -t = db.update_arraymatch5; +let t = db.update_arraymatch5; t.drop(); t.insert({abc: {visible: true}, testarray: [{foobar_id: 316, visible: true, xxx: 1}]}); diff --git a/jstests/core/write/update/update_arraymatch6.js b/jstests/core/write/update/update_arraymatch6.js index f8be918b826..16563e8d3e5 100644 --- a/jstests/core/write/update/update_arraymatch6.js +++ b/jstests/core/write/update/update_arraymatch6.js @@ -4,7 +4,7 @@ // @tags: [assumes_unsharded_collection] var res; -t = db.jstests_update_arraymatch6; +let t = db.jstests_update_arraymatch6; t.drop(); function doTest() { diff --git a/jstests/core/write/update/update_arraymatch7.js b/jstests/core/write/update/update_arraymatch7.js index cded4ba56f4..552c8469dd1 100644 --- a/jstests/core/write/update/update_arraymatch7.js +++ b/jstests/core/write/update/update_arraymatch7.js @@ -6,7 +6,7 @@ // Check that the positional operator works properly when an index only match is used for the update // query spec. SERVER-5067 -t = db.jstests_update_arraymatch7; +let t = db.jstests_update_arraymatch7; t.drop(); function testPositionalInc() { diff --git a/jstests/core/write/update/update_arraymatch8.js b/jstests/core/write/update/update_arraymatch8.js index e3aa91d6422..2f5365352e2 100644 --- a/jstests/core/write/update/update_arraymatch8.js +++ b/jstests/core/write/update/update_arraymatch8.js @@ -9,7 +9,7 @@ // SERVER-7511 // array.$.name -t = db.jstests_update_arraymatch8; +let t = db.jstests_update_arraymatch8; t.drop(); t.createIndex({'array.name': 1}); t.insert({'array': [{'name': 'old'}]}); @@ -51,7 +51,7 @@ assert(!t.findOne({'array.name': 'old'})); // // array.12.name t = db.jstests_update_arraymatch8; t.drop(); -arr = new Array(); +let arr = new Array(); for (var i = 0; i < 20; i++) { arr.push({'name': 'old'}); } diff --git a/jstests/core/write/update/update_blank1.js b/jstests/core/write/update/update_blank1.js index cd8f7433ebe..0e643f890b0 100644 --- a/jstests/core/write/update/update_blank1.js +++ b/jstests/core/write/update/update_blank1.js @@ -3,15 +3,10 @@ // key. // @tags: [assumes_unsharded_collection] -t = db.update_blank1; +let t = db.update_blank1; t.drop(); -orig = { - "": 1, - _id: 2, - "a": 3, - "b": 4 -}; +let orig = {"": 1, _id: 2, "a": 3, "b": 4}; t.insert(orig); var res = t.update({}, {$set: {"c": 5}}); print(res); diff --git a/jstests/core/write/update/update_dbref.js b/jstests/core/write/update/update_dbref.js index f3e461c7379..caaff55cc91 100644 --- a/jstests/core/write/update/update_dbref.js +++ b/jstests/core/write/update/update_dbref.js @@ -8,7 +8,7 @@ // Test that we can update DBRefs, but not dbref fields outside a DBRef var res; -t = db.jstests_update_dbref; +let t = db.jstests_update_dbref; t.drop(); res = t.save({_id: 1, a: new DBRef("a", "b")}); diff --git a/jstests/core/write/update/update_invalid1.js b/jstests/core/write/update/update_invalid1.js index bbda4cee53e..7276d33e5ef 100644 --- a/jstests/core/write/update/update_invalid1.js +++ b/jstests/core/write/update/update_invalid1.js @@ -2,7 +2,7 @@ // requires_fastcount, // ] -t = db.update_invalid1; +let t = db.update_invalid1; t.drop(); t.update({_id: 5}, {$set: {$inc: {x: 5}}}, true); diff --git a/jstests/core/write/update/update_multi3.js b/jstests/core/write/update/update_multi3.js index 4c6769bc65a..463d4192ad9 100644 --- a/jstests/core/write/update/update_multi3.js +++ b/jstests/core/write/update/update_multi3.js @@ -1,6 +1,6 @@ // @tags: [requires_multi_updates, requires_non_retryable_writes] -t = db.update_multi3; +let t = db.update_multi3; function test(useIndex) { t.drop(); @@ -8,7 +8,7 @@ function test(useIndex) { if (useIndex) t.createIndex({k: 1}); - for (i = 0; i < 10; i++) { + for (let i = 0; i < 10; i++) { t.save({_id: i, k: 'x', a: []}); } diff --git a/jstests/core/write/update/update_multi4.js b/jstests/core/write/update/update_multi4.js index cfe11616efc..d0e868ee5dd 100644 --- a/jstests/core/write/update/update_multi4.js +++ b/jstests/core/write/update/update_multi4.js @@ -1,9 +1,9 @@ // @tags: [requires_multi_updates, requires_non_retryable_writes] -t = db.update_mulit4; +let t = db.update_mulit4; t.drop(); -for (i = 0; i < 1000; i++) { +for (let i = 0; i < 1000; i++) { t.insert({_id: i, k: i % 12, v: "v" + i % 12}); } diff --git a/jstests/core/write/update/update_multi6.js b/jstests/core/write/update/update_multi6.js index 023398534cd..217da4c002d 100644 --- a/jstests/core/write/update/update_multi6.js +++ b/jstests/core/write/update/update_multi6.js @@ -2,7 +2,7 @@ var res; -t = db.update_multi6; +let t = db.update_multi6; t.drop(); t.update({_id: 1}, {_id: 1, x: 1, y: 2}, true, false); diff --git a/jstests/core/write/update/update_setOnInsert.js b/jstests/core/write/update/update_setOnInsert.js index 9457c69f325..6e3f757660f 100644 --- a/jstests/core/write/update/update_setOnInsert.js +++ b/jstests/core/write/update/update_setOnInsert.js @@ -1,5 +1,5 @@ // This tests that $setOnInsert works and allow setting the _id -t = db.update_setOnInsert; +let t = db.update_setOnInsert; var res; function dotest(useIndex) { diff --git a/jstests/core/write/update/updatea.js b/jstests/core/write/update/updatea.js index 99938c433fa..23dda37054b 100644 --- a/jstests/core/write/update/updatea.js +++ b/jstests/core/write/update/updatea.js @@ -4,13 +4,10 @@ // @tags: [assumes_unsharded_collection] var res; -t = db.updatea; +let t = db.updatea; t.drop(); -orig = { - _id: 1, - a: [{x: 1, y: 2}, {x: 10, y: 11}] -}; +let orig = {_id: 1, a: [{x: 1, y: 2}, {x: 10, y: 11}]}; res = t.save(orig); assert.commandWorked(res); @@ -52,7 +49,7 @@ orig = { _id: 1, a: [] }; -for (i = 0; i < 12; i++) +for (let i = 0; i < 12; i++) orig.a.push(i); res = t.save(orig); diff --git a/jstests/core/write/update/updateb.js b/jstests/core/write/update/updateb.js index 1518e7f3546..cea484a2732 100644 --- a/jstests/core/write/update/updateb.js +++ b/jstests/core/write/update/updateb.js @@ -3,15 +3,12 @@ // key. // @tags: [assumes_unsharded_collection] -t = db.updateb; +let t = db.updateb; t.drop(); t.update({"x.y": 2}, {$inc: {a: 7}}, true); -correct = { - a: 7, - x: {y: 2} -}; -got = t.findOne(); +let correct = {a: 7, x: {y: 2}}; +let got = t.findOne(); delete got._id; assert.docEq(correct, got, "A"); diff --git a/jstests/core/write/update/updatec.js b/jstests/core/write/update/updatec.js index 8ce8cf4ecdd..e47ed3ff797 100644 --- a/jstests/core/write/update/updatec.js +++ b/jstests/core/write/update/updatec.js @@ -1,5 +1,5 @@ -t = db.updatec; +let t = db.updatec; t.drop(); t.update({"_id": 123}, {$set: {"v": {"i": 123, "a": 456}}, $push: {"f": 234}}, 1, 0); diff --git a/jstests/core/write/update/updated.js b/jstests/core/write/update/updated.js index 919d02610c7..d850181afb5 100644 --- a/jstests/core/write/update/updated.js +++ b/jstests/core/write/update/updated.js @@ -3,13 +3,10 @@ // key. // @tags: [assumes_unsharded_collection] -t = db.updated; +let t = db.updated; t.drop(); -o = { - _id: Math.random(), - items: [null, null, null, null] -}; +let o = {_id: Math.random(), items: [null, null, null, null]}; t.insert(o); assert.docEq(o, t.findOne(), "A1"); diff --git a/jstests/core/write/update/updatee.js b/jstests/core/write/update/updatee.js index fbbcac01c9a..ed2c3a0d81c 100644 --- a/jstests/core/write/update/updatee.js +++ b/jstests/core/write/update/updatee.js @@ -5,7 +5,7 @@ // big numeric updates (used to overflow) -t = db.updatee; +let t = db.updatee; t.drop(); var o = { diff --git a/jstests/core/write/update/updatef.js b/jstests/core/write/update/updatef.js index 6597484f78a..3a55a38d954 100644 --- a/jstests/core/write/update/updatef.js +++ b/jstests/core/write/update/updatef.js @@ -7,24 +7,24 @@ // Test unsafe management of nsdt on update command yield SERVER-3208 -prefixNS = db.jstests_updatef; +let prefixNS = db.jstests_updatef; prefixNS.save({}); -t = db.jstests_updatef_actual; +let t = db.jstests_updatef_actual; t.drop(); t.save({a: 0, b: []}); -for (i = 0; i < 1000; ++i) { +for (let i = 0; i < 1000; ++i) { t.save({a: 100}); } t.save({a: 0, b: []}); // Repeatedly rename jstests_updatef to jstests_updatef_ and back. This will // invalidate the jstests_updatef_actual NamespaceDetailsTransient object. -s = startParallelShell( +let s = startParallelShell( "for( i=0; i < 100; ++i ) { db.jstests_updatef.renameCollection( 'jstests_updatef_' ); db.jstests_updatef_.renameCollection( 'jstests_updatef' ); }"); -for (i = 0; i < 20; ++i) { +for (let i = 0; i < 20; ++i) { t.update({a: 0}, {$push: {b: i}}, false, true); } diff --git a/jstests/core/write/update/updateg.js b/jstests/core/write/update/updateg.js index 8a849a0ce59..b014547b3e2 100644 --- a/jstests/core/write/update/updateg.js +++ b/jstests/core/write/update/updateg.js @@ -5,7 +5,7 @@ // SERVER-3370 check modifiers with field name characters comparing less than '.' character. -t = db.jstests_updateg; +let t = db.jstests_updateg; t.drop(); t.update({}, {'$inc': {'all.t': 1, 'all-copy.t': 1}}, true); diff --git a/jstests/core/write/update/updateh.js b/jstests/core/write/update/updateh.js index 72d0d22c616..bafebc08ed7 100644 --- a/jstests/core/write/update/updateh.js +++ b/jstests/core/write/update/updateh.js @@ -7,7 +7,7 @@ var res; -t = db.jstest_updateh; +let t = db.jstest_updateh; t.drop(); t.insert({x: 1}); diff --git a/jstests/core/write/update/updatei.js b/jstests/core/write/update/updatei.js index 599c9538a80..c5b7875df51 100644 --- a/jstests/core/write/update/updatei.js +++ b/jstests/core/write/update/updatei.js @@ -5,13 +5,13 @@ // Test new (optional) update syntax // SERVER-4176 -t = db.updatei; +let t = db.updatei; // Using a multi update t.drop(); -for (i = 0; i < 10; i++) { +for (let i = 0; i < 10; i++) { t.save({_id: i, k: "x", a: []}); } @@ -24,7 +24,7 @@ t.drop(); // Using a single update -for (i = 0; i < 10; i++) { +for (let i = 0; i < 10; i++) { t.save({_id: i, k: "x", a: []}); } @@ -35,7 +35,7 @@ t.drop(); // Using upsert, found -for (i = 0; i < 10; i++) { +for (let i = 0; i < 10; i++) { t.save({_id: i, k: "x", a: []}); } @@ -46,7 +46,7 @@ t.drop(); // Using upsert + multi, found -for (i = 0; i < 10; i++) { +for (let i = 0; i < 10; i++) { t.save({_id: i, k: "x", a: []}); } @@ -59,7 +59,7 @@ t.drop(); // Using upsert, not found -for (i = 0; i < 10; i++) { +for (let i = 0; i < 10; i++) { t.save({_id: i, k: "x", a: []}); } @@ -70,7 +70,7 @@ t.drop(); // Without upsert, found -for (i = 0; i < 10; i++) { +for (let i = 0; i < 10; i++) { t.save({_id: i, k: "x", a: []}); } @@ -81,7 +81,7 @@ t.drop(); // Without upsert, not found -for (i = 0; i < 10; i++) { +for (let i = 0; i < 10; i++) { t.save({_id: i, k: "x", a: []}); } diff --git a/jstests/core/write/update/updatej.js b/jstests/core/write/update/updatej.js index bab2a32f45f..77c5f52cbcf 100644 --- a/jstests/core/write/update/updatej.js +++ b/jstests/core/write/update/updatej.js @@ -5,7 +5,7 @@ // encounters an error. // @tags: [requires_multi_updates, requires_non_retryable_writes, assumes_unsharded_collection] -t = db.jstests_updatej; +let t = db.jstests_updatej; t.drop(); t.save({a: []}); diff --git a/jstests/core/write/update/updatek.js b/jstests/core/write/update/updatek.js index 923b4145d1d..4ef4fe8ddb9 100644 --- a/jstests/core/write/update/updatek.js +++ b/jstests/core/write/update/updatek.js @@ -5,7 +5,7 @@ // Test modifier operations on numerically equivalent string field names. SERVER-4776 -t = db.jstests_updatek; +let t = db.jstests_updatek; t.drop(); t.save({_id: 0, '1': {}, '01': {}}); diff --git a/jstests/core/write/update/updatel.js b/jstests/core/write/update/updatel.js index a663f306722..332fad0c6ec 100644 --- a/jstests/core/write/update/updatel.js +++ b/jstests/core/write/update/updatel.js @@ -8,7 +8,7 @@ // setinel ('$'), the update fails with an error. SERVER-6669 SERVER-4713 var res; -t = db.jstests_updatel; +let t = db.jstests_updatel; t.drop(); // The collection is empty, forcing an upsert. In this case the query has no array position match diff --git a/jstests/core/write/update/updatem.js b/jstests/core/write/update/updatem.js index 8e4af7e56c7..0dd0fcba014 100644 --- a/jstests/core/write/update/updatem.js +++ b/jstests/core/write/update/updatem.js @@ -7,7 +7,7 @@ // Tests that _id will exist in all updated docs. -t = db.jstests_updatem; +let t = db.jstests_updatem; t.drop(); // new _id from insert (upsert:true) diff --git a/jstests/core/write/update/upsert_and.js b/jstests/core/write/update/upsert_and.js index 1e45cbe8dc2..c2bab3ab25c 100644 --- a/jstests/core/write/update/upsert_and.js +++ b/jstests/core/write/update/upsert_and.js @@ -5,7 +5,7 @@ // tests to ensure fields in $and conditions are created when using the query to do upsert var res; -coll = db.upsert4; +let coll = db.upsert4; coll.drop(); res = coll.update({_id: 1, $and: [{c: 1}, {d: 1}], a: 12}, {$inc: {y: 1}}, true); diff --git a/jstests/core/write/update/upsert_fields.js b/jstests/core/write/update/upsert_fields.js index 310bace4907..0433b15048b 100644 --- a/jstests/core/write/update/upsert_fields.js +++ b/jstests/core/write/update/upsert_fields.js @@ -12,7 +12,7 @@ coll.drop(); var upsertedResult = function(query, expr) { coll.drop(); - result = coll.update(query, expr, {upsert: true}); + let result = coll.update(query, expr, {upsert: true}); return result; }; diff --git a/jstests/core/write/update/upsert_shell.js b/jstests/core/write/update/upsert_shell.js index 3ab07b50c21..252a0f4139a 100644 --- a/jstests/core/write/update/upsert_shell.js +++ b/jstests/core/write/update/upsert_shell.js @@ -5,7 +5,7 @@ // tests to make sure that the new _id is returned after the insert in the shell var l; -t = db.upsert1; +let t = db.upsert1; t.drop(); // make sure the new _id is returned when $mods are used diff --git a/jstests/core/write/validate_user_documents.js b/jstests/core/write/validate_user_documents.js index 2a30ed0fea8..65aa7cde07e 100644 --- a/jstests/core/write/validate_user_documents.js +++ b/jstests/core/write/validate_user_documents.js @@ -10,7 +10,7 @@ // Ensure that inserts and updates of the system.users collection validate the schema of inserted // documents. -mydb = db.getSiblingDB("validate_user_documents"); +let mydb = db.getSiblingDB("validate_user_documents"); function assertGLEOK(status) { assert(status.ok && status.err === null, "Expected OK status object; found " + tojson(status)); |