summaryrefslogtreecommitdiff
path: root/jstests/core
diff options
context:
space:
mode:
authorMatthew Russotto <matthew.russotto@mongodb.com>2022-11-09 15:40:59 -0500
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2022-11-10 20:01:33 +0000
commit37c1feb59ee356cc0ab91873519c5cba00bc9115 (patch)
tree1245228a45973fe74bd969d5e4e465393cc018f9 /jstests/core
parente5422893b3136085aedf9b9692e92b15f5cca84d (diff)
downloadmongo-37c1feb59ee356cc0ab91873519c5cba00bc9115.tar.gz
SERVER-71225 Make sure collation.js does not change 'db'
Diffstat (limited to 'jstests/core')
-rw-r--r--jstests/core/collation.js418
1 files changed, 210 insertions, 208 deletions
diff --git a/jstests/core/collation.js b/jstests/core/collation.js
index faf76353bf9..c84371bddbc 100644
--- a/jstests/core/collation.js
+++ b/jstests/core/collation.js
@@ -28,19 +28,19 @@ load("jstests/libs/sbe_explain_helpers.js"); // For engineSpecificAssertion.
// For areAllCollectionsClustered.
load("jstests/libs/clustered_collections/clustered_collection_util.js");
-db = db.getSiblingDB("collation_js");
-var coll = db.collation;
+let testDb = db.getSiblingDB("collation_js");
+var coll = testDb.collation;
coll.drop();
var explainRes;
var writeRes;
var planStage;
-var hello = db.runCommand("hello");
+var hello = testDb.runCommand("hello");
assert.commandWorked(hello);
var isMongos = (hello.msg === "isdbgrid");
var isStandalone = !isMongos && !hello.hasOwnProperty('setName');
-var isClustered = ClusteredCollectionUtil.areAllCollectionsClustered(db);
+var isClustered = ClusteredCollectionUtil.areAllCollectionsClustered(testDb);
var assertIndexHasCollation = function(keyPattern, collation) {
var indexSpecs = coll.getIndexes();
@@ -66,36 +66,38 @@ var getQueryCollation = function(explainRes) {
};
//
-// Test using db.createCollection() to make a collection with a default collation.
+// Test using testDb.createCollection() to make a collection with a default collation.
//
// Attempting to create a collection with an invalid collation should fail.
-assert.commandFailed(db.createCollection("collation", {collation: "not an object"}));
-assert.commandFailed(db.createCollection("collation", {collation: {}}));
-assert.commandFailed(db.createCollection("collation", {collation: {blah: 1}}));
-assert.commandFailed(db.createCollection("collation", {collation: {locale: "en", blah: 1}}));
-assert.commandFailed(db.createCollection("collation", {collation: {locale: "xx"}}));
-assert.commandFailed(db.createCollection("collation", {collation: {locale: "en", strength: 99}}));
-assert.commandFailed(db.createCollection("collation", {collation: {locale: "en", strength: 9.9}}));
+assert.commandFailed(testDb.createCollection("collation", {collation: "not an object"}));
+assert.commandFailed(testDb.createCollection("collation", {collation: {}}));
+assert.commandFailed(testDb.createCollection("collation", {collation: {blah: 1}}));
+assert.commandFailed(testDb.createCollection("collation", {collation: {locale: "en", blah: 1}}));
+assert.commandFailed(testDb.createCollection("collation", {collation: {locale: "xx"}}));
+assert.commandFailed(
+ testDb.createCollection("collation", {collation: {locale: "en", strength: 99}}));
+assert.commandFailed(
+ testDb.createCollection("collation", {collation: {locale: "en", strength: 9.9}}));
// Attempting to create a collection whose collation version does not match the collator version
// produced by ICU should result in failure with a special error code.
assert.commandFailedWithCode(
- db.createCollection("collation", {collation: {locale: "en", version: "unknownVersion"}}),
+ testDb.createCollection("collation", {collation: {locale: "en", version: "unknownVersion"}}),
ErrorCodes.IncompatibleCollationVersion);
// Ensure we can create a collection with the "simple" collation as the collection default.
-assert.commandWorked(db.createCollection(coll.getName(), {collation: {locale: "simple"}}));
-var collectionInfos = db.getCollectionInfos({name: coll.getName()});
+assert.commandWorked(testDb.createCollection(coll.getName(), {collation: {locale: "simple"}}));
+var collectionInfos = testDb.getCollectionInfos({name: coll.getName()});
assert.eq(collectionInfos.length, 1);
assert(!collectionInfos[0].options.hasOwnProperty("collation"));
// Ensure that we populate all collation-related fields when we create a collection with a valid
// collation.
-coll = db.collation_frCA;
+coll = testDb.collation_frCA;
coll.drop();
-assert.commandWorked(db.createCollection(coll.getName(), {collation: {locale: "fr_CA"}}));
-var collectionInfos = db.getCollectionInfos({name: coll.getName()});
+assert.commandWorked(testDb.createCollection(coll.getName(), {collation: {locale: "fr_CA"}}));
+var collectionInfos = testDb.getCollectionInfos({name: coll.getName()});
assert.eq(collectionInfos.length, 1);
assert.eq(collectionInfos[0].options.collation, {
locale: "fr_CA",
@@ -182,7 +184,7 @@ if (isStandalone) {
assertIndexHasCollation({c: 1}, {locale: "simple"});
}
-coll = db.collation_index1;
+coll = testDb.collation_index1;
coll.drop();
//
// Creating an index with a collation.
@@ -261,7 +263,7 @@ assertIndexHasCollation({e: 1}, {locale: "simple"});
// Test that an index with a non-simple collation contains collator-generated comparison keys
// rather than the verbatim indexed strings.
-coll = db.collation_index2;
+coll = testDb.collation_index2;
coll.drop();
assert.commandWorked(coll.createIndex({a: 1}, {collation: {locale: "fr_CA"}}));
assert.commandWorked(coll.createIndex({b: 1}));
@@ -273,41 +275,41 @@ assert.eq("foo", coll.find().collation({locale: "fr_CA"}).hint({b: 1}).returnKey
// Test that a query with a string comparison can use an index with a non-simple collation if it
// has a matching collation.
-coll = db.collation_index3;
+coll = testDb.collation_index3;
coll.drop();
assert.commandWorked(coll.createIndex({a: 1}, {collation: {locale: "fr_CA"}}));
// Query has simple collation, but index has fr_CA collation.
explainRes = coll.find({a: "foo"}).explain();
assert.commandWorked(explainRes);
-assert(planHasStage(db, getWinningPlan(explainRes.queryPlanner), "COLLSCAN"));
+assert(planHasStage(testDb, getWinningPlan(explainRes.queryPlanner), "COLLSCAN"));
// Query has en_US collation, but index has fr_CA collation.
explainRes = coll.find({a: "foo"}).collation({locale: "en_US"}).explain();
assert.commandWorked(explainRes);
-assert(planHasStage(db, getWinningPlan(explainRes.queryPlanner), "COLLSCAN"));
+assert(planHasStage(testDb, getWinningPlan(explainRes.queryPlanner), "COLLSCAN"));
// Matching collations.
explainRes = coll.find({a: "foo"}).collation({locale: "fr_CA"}).explain();
assert.commandWorked(explainRes);
-assert(planHasStage(db, getWinningPlan(explainRes.queryPlanner), "IXSCAN"));
+assert(planHasStage(testDb, getWinningPlan(explainRes.queryPlanner), "IXSCAN"));
// Should not be possible to create a text index with an explicit non-simple collation.
-coll = db.collation_index3;
+coll = testDb.collation_index3;
coll.drop();
assert.commandFailed(coll.createIndex({a: "text"}, {collation: {locale: "en"}}));
// Text index builds which inherit a non-simple default collation should fail.
-coll = db.collation_en1;
+coll = testDb.collation_en1;
coll.drop();
-assert.commandWorked(db.createCollection(coll.getName(), {collation: {locale: "en"}}));
+assert.commandWorked(testDb.createCollection(coll.getName(), {collation: {locale: "en"}}));
assert.commandFailed(coll.createIndex({a: "text"}));
// Text index build should succeed on a collection with a non-simple default collation if it
// explicitly overrides the default with {locale: "simple"}.
-coll = db.collation_en2;
+coll = testDb.collation_en2;
coll.drop();
-assert.commandWorked(db.createCollection(coll.getName(), {collation: {locale: "en"}}));
+assert.commandWorked(testDb.createCollection(coll.getName(), {collation: {locale: "en"}}));
assert.commandWorked(coll.createIndex({a: "text"}, {collation: {locale: "simple"}}));
//
@@ -316,12 +318,12 @@ assert.commandWorked(coll.createIndex({a: "text"}, {collation: {locale: "simple"
// Aggregation should return correct results when collation specified and collection does not
// exist.
-coll = db.collation_agg1;
+coll = testDb.collation_agg1;
coll.drop();
assert.eq(0, coll.aggregate([], {collation: {locale: "fr"}}).itcount());
// Aggregation should return correct results when collation specified and collection does exist.
-coll = db.collation_agg2;
+coll = testDb.collation_agg2;
coll.drop();
assert.commandWorked(coll.insert({_id: 1, str: "foo"}));
assert.commandWorked(coll.insert({_id: 2, str: "bar"}));
@@ -332,39 +334,39 @@ assert.eq(1,
// Aggregation should return correct results when no collation specified and collection has a
// default collation.
-coll = db.collation_agg3;
+coll = testDb.collation_agg3;
coll.drop();
assert.commandWorked(
- db.createCollection(coll.getName(), {collation: {locale: "en_US", strength: 2}}));
+ testDb.createCollection(coll.getName(), {collation: {locale: "en_US", strength: 2}}));
assert.commandWorked(coll.insert({str: "foo"}));
assert.eq(1, coll.aggregate([{$match: {str: "FOO"}}]).itcount());
// Aggregation should return correct results when "simple" collation specified and collection
// has a default collation.
-coll = db.collation_agg4;
+coll = testDb.collation_agg4;
coll.drop();
assert.commandWorked(
- db.createCollection(coll.getName(), {collation: {locale: "en_US", strength: 2}}));
+ testDb.createCollection(coll.getName(), {collation: {locale: "en_US", strength: 2}}));
assert.commandWorked(coll.insert({str: "foo"}));
assert.eq(0, coll.aggregate([{$match: {str: "FOO"}}], {collation: {locale: "simple"}}).itcount());
// Aggregation should select compatible index when no collation specified and collection has a
// default collation.
-coll = db.collation_agg5;
+coll = testDb.collation_agg5;
coll.drop();
-assert.commandWorked(db.createCollection(coll.getName(), {collation: {locale: "en_US"}}));
+assert.commandWorked(testDb.createCollection(coll.getName(), {collation: {locale: "en_US"}}));
assert.commandWorked(coll.createIndex({a: 1}, {collation: {locale: "en_US"}}));
var explain = coll.explain("queryPlanner").aggregate([{$match: {a: "foo"}}]);
-assert(isIxscan(db, getWinningPlan(explain.queryPlanner)));
+assert(isIxscan(testDb, getWinningPlan(explain.queryPlanner)));
// Aggregation should not use index when no collation specified and collection default
// collation is incompatible with index collation.
-coll = db.collation_agg6;
+coll = testDb.collation_agg6;
coll.drop();
-assert.commandWorked(db.createCollection(coll.getName(), {collation: {locale: "en_US"}}));
+assert.commandWorked(testDb.createCollection(coll.getName(), {collation: {locale: "en_US"}}));
assert.commandWorked(coll.createIndex({a: 1}, {collation: {locale: "simple"}}));
var explain = coll.explain("queryPlanner").aggregate([{$match: {a: "foo"}}]);
-assert(isCollscan(db, getWinningPlan(explain.queryPlanner)));
+assert(isCollscan(testDb, getWinningPlan(explain.queryPlanner)));
// Explain of aggregation with collation should succeed.
assert.commandWorked(coll.explain().aggregate([], {collation: {locale: "fr"}}));
@@ -374,12 +376,12 @@ assert.commandWorked(coll.explain().aggregate([], {collation: {locale: "fr"}}));
//
// Count should return correct results when collation specified and collection does not exist.
-coll = db.collation_count1;
+coll = testDb.collation_count1;
coll.drop();
assert.eq(0, coll.find({str: "FOO"}).collation({locale: "en_US"}).count());
// Count should return correct results when collation specified and collection does exist.
-coll = db.collation_count1;
+coll = testDb.collation_count1;
coll.drop();
assert.commandWorked(coll.insert({_id: 1, str: "foo"}));
assert.commandWorked(coll.insert({_id: 2, str: "bar"}));
@@ -392,24 +394,24 @@ assert.eq(1, coll.count({str: "FOO"}, {collation: {locale: "en_US", strength: 2}
// Count should return correct results when no collation specified and collection has a default
// collation.
-coll = db.collation_count3;
+coll = testDb.collation_count3;
coll.drop();
assert.commandWorked(
- db.createCollection(coll.getName(), {collation: {locale: "en_US", strength: 2}}));
+ testDb.createCollection(coll.getName(), {collation: {locale: "en_US", strength: 2}}));
assert.commandWorked(coll.insert({str: "foo"}));
assert.eq(1, coll.find({str: "FOO"}).count());
// Count should return correct results when "simple" collation specified and collection has a
// default collation.
-coll = db.collation_count4;
+coll = testDb.collation_count4;
coll.drop();
assert.commandWorked(
- db.createCollection(coll.getName(), {collation: {locale: "en_US", strength: 2}}));
+ testDb.createCollection(coll.getName(), {collation: {locale: "en_US", strength: 2}}));
assert.commandWorked(coll.insert({str: "foo"}));
assert.eq(0, coll.find({str: "FOO"}).collation({locale: "simple"}).count());
// Count should return correct results when collation specified and when run with explain.
-coll = db.collation_count5;
+coll = testDb.collation_count5;
coll.drop();
assert.commandWorked(coll.insert({_id: 1, str: "foo"}));
assert.commandWorked(coll.insert({_id: 2, str: "bar"}));
@@ -428,7 +430,7 @@ assert.neq(null, planStage);
assert.eq(1, planStage.advanced);
// Explain of COUNT_SCAN stage should include index collation.
-coll = db.collation_count6;
+coll = testDb.collation_count6;
coll.drop();
assert.commandWorked(coll.createIndex({a: 1}, {collation: {locale: "fr_CA"}}));
explainRes = coll.explain("executionStats").find({a: 5}).count();
@@ -450,9 +452,9 @@ assert.eq(planStage.collation, {
// Explain of COUNT_SCAN stage should include index collation when index collation is
// inherited from collection default.
-coll = db.collation_count7;
+coll = testDb.collation_count7;
coll.drop();
-assert.commandWorked(db.createCollection(coll.getName(), {collation: {locale: "fr_CA"}}));
+assert.commandWorked(testDb.createCollection(coll.getName(), {collation: {locale: "fr_CA"}}));
assert.commandWorked(coll.createIndex({a: 1}));
explainRes = coll.explain("executionStats").find({a: 5}).count();
assert.commandWorked(explainRes);
@@ -472,14 +474,14 @@ assert.eq(planStage.collation, {
});
// Should be able to use COUNT_SCAN for queries over strings.
-coll = db.collation_count8;
+coll = testDb.collation_count8;
coll.drop();
-assert.commandWorked(db.createCollection(coll.getName(), {collation: {locale: "fr_CA"}}));
+assert.commandWorked(testDb.createCollection(coll.getName(), {collation: {locale: "fr_CA"}}));
assert.commandWorked(coll.createIndex({a: 1}));
explainRes = coll.explain("executionStats").find({a: "foo"}).count();
assert.commandWorked(explainRes);
-assert(planHasStage(db, explainRes.executionStats.executionStages, "COUNT_SCAN"));
-assert(!planHasStage(db, explainRes.executionStats.executionStages, "FETCH"));
+assert(planHasStage(testDb, explainRes.executionStats.executionStages, "COUNT_SCAN"));
+assert(!planHasStage(testDb, explainRes.executionStats.executionStages, "FETCH"));
//
// Collation tests for distinct.
@@ -487,12 +489,12 @@ assert(!planHasStage(db, explainRes.executionStats.executionStages, "FETCH"));
// Distinct should return correct results when collation specified and collection does not
// exist.
-coll = db.collation_distinct1;
+coll = testDb.collation_distinct1;
coll.drop();
assert.eq(0, coll.distinct("str", {}, {collation: {locale: "en_US", strength: 2}}).length);
// Distinct should return correct results when collation specified and no indexes exist.
-coll = db.collation_distinct2;
+coll = testDb.collation_distinct2;
coll.drop();
assert.commandWorked(coll.insert({_id: 1, str: "foo"}));
assert.commandWorked(coll.insert({_id: 2, str: "FOO"}));
@@ -512,10 +514,10 @@ assert.eq(2, coll.distinct("str", {}, {collation: {locale: "en_US", strength: 3}
// Distinct should return correct results when no collation specified and collection has a
// default collation.
-coll = db.collation_distinct3;
+coll = testDb.collation_distinct3;
coll.drop();
assert.commandWorked(
- db.createCollection(coll.getName(), {collation: {locale: "en_US", strength: 2}}));
+ testDb.createCollection(coll.getName(), {collation: {locale: "en_US", strength: 2}}));
assert.commandWorked(coll.insert({str: "foo"}));
assert.commandWorked(coll.insert({str: "FOO"}));
assert.eq(1, coll.distinct("str").length);
@@ -523,10 +525,10 @@ assert.eq(2, coll.distinct("_id", {str: "foo"}).length);
// Distinct should return correct results when "simple" collation specified and collection has a
// default collation.
-coll = db.collation_distinct4;
+coll = testDb.collation_distinct4;
coll.drop();
assert.commandWorked(
- db.createCollection(coll.getName(), {collation: {locale: "en_US", strength: 2}}));
+ testDb.createCollection(coll.getName(), {collation: {locale: "en_US", strength: 2}}));
assert.commandWorked(coll.insert({str: "foo"}));
assert.commandWorked(coll.insert({str: "FOO"}));
assert.eq(2, coll.distinct("str", {}, {collation: {locale: "simple"}}).length);
@@ -534,45 +536,45 @@ assert.eq(1, coll.distinct("_id", {str: "foo"}, {collation: {locale: "simple"}})
// Distinct should select compatible index when no collation specified and collection has a
// default collation.
-coll = db.collation_distinct5;
+coll = testDb.collation_distinct5;
coll.drop();
-assert.commandWorked(db.createCollection(coll.getName(), {collation: {locale: "en_US"}}));
+assert.commandWorked(testDb.createCollection(coll.getName(), {collation: {locale: "en_US"}}));
assert.commandWorked(coll.createIndex({a: 1}, {collation: {locale: "en_US"}}));
var explain = coll.explain("queryPlanner").distinct("a");
-assert(planHasStage(db, getWinningPlan(explain.queryPlanner), "DISTINCT_SCAN"));
-assert(planHasStage(db, getWinningPlan(explain.queryPlanner), "FETCH"));
+assert(planHasStage(testDb, getWinningPlan(explain.queryPlanner), "DISTINCT_SCAN"));
+assert(planHasStage(testDb, getWinningPlan(explain.queryPlanner), "FETCH"));
// Distinct scan on strings can be used over an index with a collation when the predicate has
// exact bounds.
explain = coll.explain("queryPlanner").distinct("a", {a: {$gt: "foo"}});
-assert(planHasStage(db, getWinningPlan(explain.queryPlanner), "DISTINCT_SCAN"));
-assert(planHasStage(db, getWinningPlan(explain.queryPlanner), "FETCH"));
-assert(!planHasStage(db, getWinningPlan(explain.queryPlanner), "PROJECTION_COVERED"));
+assert(planHasStage(testDb, getWinningPlan(explain.queryPlanner), "DISTINCT_SCAN"));
+assert(planHasStage(testDb, getWinningPlan(explain.queryPlanner), "FETCH"));
+assert(!planHasStage(testDb, getWinningPlan(explain.queryPlanner), "PROJECTION_COVERED"));
// Distinct scan cannot be used over an index with a collation when the predicate has inexact
// bounds.
explain = coll.explain("queryPlanner").distinct("a", {a: {$exists: true}});
-assert(planHasStage(db, getWinningPlan(explain.queryPlanner), "IXSCAN"));
-assert(planHasStage(db, getWinningPlan(explain.queryPlanner), "FETCH"));
-assert(!planHasStage(db, getWinningPlan(explain.queryPlanner), "DISTINCT_SCAN"));
+assert(planHasStage(testDb, getWinningPlan(explain.queryPlanner), "IXSCAN"));
+assert(planHasStage(testDb, getWinningPlan(explain.queryPlanner), "FETCH"));
+assert(!planHasStage(testDb, getWinningPlan(explain.queryPlanner), "DISTINCT_SCAN"));
// Distinct scan can be used without a fetch when predicate has exact non-string bounds.
explain = coll.explain("queryPlanner").distinct("a", {a: {$gt: 3}});
-assert(planHasStage(db, getWinningPlan(explain.queryPlanner), "DISTINCT_SCAN"));
-assert(planHasStage(db, getWinningPlan(explain.queryPlanner), "PROJECTION_COVERED"));
-assert(!planHasStage(db, getWinningPlan(explain.queryPlanner), "FETCH"));
+assert(planHasStage(testDb, getWinningPlan(explain.queryPlanner), "DISTINCT_SCAN"));
+assert(planHasStage(testDb, getWinningPlan(explain.queryPlanner), "PROJECTION_COVERED"));
+assert(!planHasStage(testDb, getWinningPlan(explain.queryPlanner), "FETCH"));
// Distinct should not use index when no collation specified and collection default collation is
// incompatible with index collation.
-coll = db.collation_distinct6;
+coll = testDb.collation_distinct6;
coll.drop();
-assert.commandWorked(db.createCollection(coll.getName(), {collation: {locale: "en_US"}}));
+assert.commandWorked(testDb.createCollection(coll.getName(), {collation: {locale: "en_US"}}));
assert.commandWorked(coll.createIndex({a: 1}, {collation: {locale: "simple"}}));
var explain = coll.explain("queryPlanner").distinct("a");
-assert(isCollscan(db, getWinningPlan(explain.queryPlanner)));
+assert(isCollscan(testDb, getWinningPlan(explain.queryPlanner)));
// Explain of DISTINCT_SCAN stage should include index collation.
-coll = db.collation_distinct7;
+coll = testDb.collation_distinct7;
coll.drop();
assert.commandWorked(coll.createIndex({str: 1}, {collation: {locale: "fr_CA"}}));
explainRes = coll.explain("executionStats").distinct("str", {}, {collation: {locale: "fr_CA"}});
@@ -594,9 +596,9 @@ assert.eq(planStage.collation, {
// Explain of DISTINCT_SCAN stage should include index collation when index collation is
// inherited from collection default.
-coll = db.collation_distinct8;
+coll = testDb.collation_distinct8;
coll.drop();
-assert.commandWorked(db.createCollection(coll.getName(), {collation: {locale: "fr_CA"}}));
+assert.commandWorked(testDb.createCollection(coll.getName(), {collation: {locale: "fr_CA"}}));
assert.commandWorked(coll.createIndex({str: 1}));
explainRes = coll.explain("executionStats").distinct("str");
assert.commandWorked(explainRes);
@@ -621,12 +623,12 @@ assert.eq(planStage.collation, {
// Find should return correct results when collation specified and collection does not
// exist.
-coll = db.collation_find1;
+coll = testDb.collation_find1;
coll.drop();
assert.eq(0, coll.find({_id: "FOO"}).collation({locale: "en_US"}).itcount());
// Find should return correct results when collation specified and filter is a match on _id.
-coll = db.collation_find2;
+coll = testDb.collation_find2;
coll.drop();
assert.commandWorked(coll.insert({_id: 1, str: "foo"}));
assert.commandWorked(coll.insert({_id: 2, str: "bar"}));
@@ -670,7 +672,7 @@ assert.commandWorked(coll.dropIndexes());
// Queries that use a index with a non-matching collation should add a sort
// stage if needed.
-coll = db.collation_find3;
+coll = testDb.collation_find3;
coll.drop();
assert.commandWorked(coll.insert([{a: "A"}, {a: "B"}, {a: "b"}, {a: "a"}]));
@@ -683,7 +685,7 @@ res = coll.find({a: {'$exists': true}}, {_id: 0}).collation({locale: "en_US", st
assert.eq(res.toArray(), [{a: "a"}, {a: "A"}, {a: "b"}, {a: "B"}]);
// Find should return correct results when collation specified and query contains $expr.
-coll = db.collation_find4;
+coll = testDb.collation_find4;
coll.drop();
assert.commandWorked(coll.insert([{a: "A"}, {a: "B"}]));
assert.eq(
@@ -691,10 +693,10 @@ assert.eq(
// Find should return correct results when no collation specified and collection has a default
// collation.
-coll = db.collation_find5;
+coll = testDb.collation_find5;
coll.drop();
assert.commandWorked(
- db.createCollection(coll.getName(), {collation: {locale: "en_US", strength: 2}}));
+ testDb.createCollection(coll.getName(), {collation: {locale: "en_US", strength: 2}}));
assert.commandWorked(coll.insert({str: "foo"}));
assert.commandWorked(coll.insert({str: "FOO"}));
assert.commandWorked(coll.insert({str: "bar"}));
@@ -706,28 +708,28 @@ assert.eq([{str: "bar"}, {str: "foo"}, {str: "FOO"}],
// Find with idhack should return correct results when no collation specified and collection has
// a default collation.
-coll = db.collation_find6;
+coll = testDb.collation_find6;
coll.drop();
assert.commandWorked(
- db.createCollection(coll.getName(), {collation: {locale: "en_US", strength: 2}}));
+ testDb.createCollection(coll.getName(), {collation: {locale: "en_US", strength: 2}}));
assert.commandWorked(coll.insert({_id: "foo"}));
assert.eq(1, coll.find({_id: "FOO"}).itcount());
// Find should return correct results for query containing $expr when no collation specified and
// collection has a default collation.
-coll = db.collation_find7;
+coll = testDb.collation_find7;
coll.drop();
assert.commandWorked(
- db.createCollection(coll.getName(), {collation: {locale: "en_US", strength: 2}}));
+ testDb.createCollection(coll.getName(), {collation: {locale: "en_US", strength: 2}}));
assert.commandWorked(coll.insert([{a: "A"}, {a: "B"}]));
assert.eq(1, coll.find({$expr: {$eq: ["$a", "a"]}}).itcount());
// Find should return correct results when "simple" collation specified and collection has a
// default collation.
-coll = db.collation_find8;
+coll = testDb.collation_find8;
coll.drop();
assert.commandWorked(
- db.createCollection(coll.getName(), {collation: {locale: "en_US", strength: 2}}));
+ testDb.createCollection(coll.getName(), {collation: {locale: "en_US", strength: 2}}));
assert.commandWorked(coll.insert({str: "foo"}));
assert.commandWorked(coll.insert({str: "FOO"}));
assert.commandWorked(coll.insert({str: "bar"}));
@@ -738,30 +740,30 @@ assert.eq([{str: "FOO"}, {str: "bar"}, {str: "foo"}],
// Find on _id should return correct results when query collation differs from collection
// default collation.
-coll = db.collation_find9;
+coll = testDb.collation_find9;
coll.drop();
assert.commandWorked(
- db.createCollection(coll.getName(), {collation: {locale: "en_US", strength: 3}}));
+ testDb.createCollection(coll.getName(), {collation: {locale: "en_US", strength: 3}}));
assert.commandWorked(coll.insert({_id: "foo"}));
assert.commandWorked(coll.insert({_id: "FOO"}));
assert.eq(2, coll.find({_id: "foo"}).collation({locale: "en_US", strength: 2}).itcount());
if (!isClustered) {
// Find on _id should use idhack stage when query inherits collection default collation.
- coll = db.collation_find10;
+ coll = testDb.collation_find10;
coll.drop();
- assert.commandWorked(db.createCollection(coll.getName(), {collation: {locale: "en_US"}}));
+ assert.commandWorked(testDb.createCollection(coll.getName(), {collation: {locale: "en_US"}}));
explainRes = coll.explain("executionStats").find({_id: "foo"}).finish();
assert.commandWorked(explainRes);
let classicAssert = null !== getPlanStage(getWinningPlan(explainRes.queryPlanner), "IDHACK");
let sbeAssert = null !== getPlanStage(getWinningPlan(explainRes.queryPlanner), "IXSCAN");
- engineSpecificAssertion(classicAssert, sbeAssert, db, explainRes);
+ engineSpecificAssertion(classicAssert, sbeAssert, testDb, explainRes);
// Find on _id should use idhack stage when explicitly given query collation matches
// collection default.
- coll = db.collation_find11;
+ coll = testDb.collation_find11;
coll.drop();
- assert.commandWorked(db.createCollection(coll.getName(), {collation: {locale: "en_US"}}));
+ assert.commandWorked(testDb.createCollection(coll.getName(), {collation: {locale: "en_US"}}));
explainRes =
coll.explain("executionStats").find({_id: "foo"}).collation({locale: "en_US"}).finish();
assert.commandWorked(explainRes);
@@ -769,9 +771,9 @@ if (!isClustered) {
// Find on _id should not use idhack stage when query collation does not match collection
// default.
- coll = db.collation_find12;
+ coll = testDb.collation_find12;
coll.drop();
- assert.commandWorked(db.createCollection(coll.getName(), {collation: {locale: "en_US"}}));
+ assert.commandWorked(testDb.createCollection(coll.getName(), {collation: {locale: "en_US"}}));
explainRes =
coll.explain("executionStats").find({_id: "foo"}).collation({locale: "fr_CA"}).finish();
assert.commandWorked(explainRes);
@@ -781,42 +783,42 @@ if (!isClustered) {
// Find should select compatible index when no collation specified and collection has a default
// collation.
-coll = db.collation_find13;
+coll = testDb.collation_find13;
coll.drop();
-assert.commandWorked(db.createCollection(coll.getName(), {collation: {locale: "en_US"}}));
+assert.commandWorked(testDb.createCollection(coll.getName(), {collation: {locale: "en_US"}}));
assert.commandWorked(coll.createIndex({a: 1}, {collation: {locale: "en_US"}}));
var explain = coll.find({a: "foo"}).explain("queryPlanner");
-assert(isIxscan(db, getWinningPlan(explain.queryPlanner)));
+assert(isIxscan(testDb, getWinningPlan(explain.queryPlanner)));
// Find should select compatible index when no collation specified and collection default
// collation is "simple".
-coll = db.collation_find14;
+coll = testDb.collation_find14;
coll.drop();
-assert.commandWorked(db.createCollection(coll.getName(), {collation: {locale: "simple"}}));
+assert.commandWorked(testDb.createCollection(coll.getName(), {collation: {locale: "simple"}}));
assert.commandWorked(coll.createIndex({a: 1}, {collation: {locale: "simple"}}));
var explain = coll.find({a: "foo"}).explain("queryPlanner");
-assert(isIxscan(db, getWinningPlan(explain.queryPlanner)));
+assert(isIxscan(testDb, getWinningPlan(explain.queryPlanner)));
// Find should not use index when no collation specified, index collation is "simple", and
// collection has a non-"simple" default collation.
-coll = db.collation_find15;
+coll = testDb.collation_find15;
coll.drop();
-assert.commandWorked(db.createCollection(coll.getName(), {collation: {locale: "en_US"}}));
+assert.commandWorked(testDb.createCollection(coll.getName(), {collation: {locale: "en_US"}}));
assert.commandWorked(coll.createIndex({a: 1}, {collation: {locale: "simple"}}));
var explain = coll.find({a: "foo"}).explain("queryPlanner");
-assert(isCollscan(db, getWinningPlan(explain.queryPlanner)));
+assert(isCollscan(testDb, getWinningPlan(explain.queryPlanner)));
// Find should select compatible index when "simple" collation specified and collection has a
// non-"simple" default collation.
-coll = db.collation_find16;
+coll = testDb.collation_find16;
coll.drop();
-assert.commandWorked(db.createCollection(coll.getName(), {collation: {locale: "en_US"}}));
+assert.commandWorked(testDb.createCollection(coll.getName(), {collation: {locale: "en_US"}}));
assert.commandWorked(coll.createIndex({a: 1}, {collation: {locale: "simple"}}));
var explain = coll.find({a: "foo"}).collation({locale: "simple"}).explain("queryPlanner");
-assert(isIxscan(db, getWinningPlan(explain.queryPlanner)));
+assert(isIxscan(testDb, getWinningPlan(explain.queryPlanner)));
// Find should return correct results when collation specified and run with explain.
-coll = db.collation_find17;
+coll = testDb.collation_find17;
coll.drop();
assert.commandWorked(coll.insert({str: "foo"}));
explainRes =
@@ -831,7 +833,7 @@ assert.commandWorked(explainRes);
assert.eq(1, explainRes.executionStats.nReturned);
// Explain of find should include query collation.
-coll = db.collation_find18;
+coll = testDb.collation_find18;
coll.drop();
explainRes =
coll.explain("executionStats").find({str: "foo"}).collation({locale: "fr_CA"}).finish();
@@ -850,9 +852,9 @@ assert.eq(getQueryCollation(explainRes), {
});
// Explain of find should include query collation when inherited from collection default.
-coll = db.collation_find19;
+coll = testDb.collation_find19;
coll.drop();
-assert.commandWorked(db.createCollection(coll.getName(), {collation: {locale: "fr_CA"}}));
+assert.commandWorked(testDb.createCollection(coll.getName(), {collation: {locale: "fr_CA"}}));
explainRes = coll.explain("executionStats").find({str: "foo"}).finish();
assert.commandWorked(explainRes);
assert.eq(getQueryCollation(explainRes), {
@@ -869,7 +871,7 @@ assert.eq(getQueryCollation(explainRes), {
});
// Explain of IXSCAN stage should include index collation.
-coll = db.collation_find20;
+coll = testDb.collation_find20;
coll.drop();
assert.commandWorked(coll.createIndex({str: 1}, {collation: {locale: "fr_CA"}}));
explainRes =
@@ -892,9 +894,9 @@ assert.eq(planStage.collation, {
// Explain of IXSCAN stage should include index collation when index collation is inherited from
// collection default.
-coll = db.collation_find21;
+coll = testDb.collation_find21;
coll.drop();
-assert.commandWorked(db.createCollection(coll.getName(), {collation: {locale: "fr_CA"}}));
+assert.commandWorked(testDb.createCollection(coll.getName(), {collation: {locale: "fr_CA"}}));
assert.commandWorked(coll.createIndex({str: 1}));
explainRes = coll.explain("executionStats").find({str: "foo"}).finish();
assert.commandWorked(explainRes);
@@ -919,7 +921,7 @@ assert.eq(planStage.collation, {
// findAndModify should return correct results when collation specified and collection does not
// exist.
-coll = db.collation_findmodify1;
+coll = testDb.collation_findmodify1;
coll.drop();
assert.eq(
null,
@@ -927,7 +929,7 @@ assert.eq(
{query: {str: "bar"}, update: {$set: {str: "baz"}}, new: true, collation: {locale: "fr"}}));
// Update-findAndModify should return correct results when collation specified.
-coll = db.collation_findmodify2;
+coll = testDb.collation_findmodify2;
coll.drop();
assert.commandWorked(coll.insert({_id: 1, str: "foo"}));
assert.commandWorked(coll.insert({_id: 2, str: "bar"}));
@@ -951,7 +953,7 @@ assert.neq(null, planStage);
assert.eq(1, planStage.nWouldModify);
// Delete-findAndModify should return correct results when collation specified.
-coll = db.collation_findmodify3;
+coll = testDb.collation_findmodify3;
coll.drop();
assert.commandWorked(coll.insert({_id: 1, str: "foo"}));
assert.commandWorked(coll.insert({_id: 2, str: "bar"}));
@@ -972,10 +974,10 @@ assert.eq(1, planStage.nWouldDelete);
// findAndModify should return correct results when no collation specified and collection has a
// default collation.
-coll = db.collation_findmodify4;
+coll = testDb.collation_findmodify4;
coll.drop();
assert.commandWorked(
- db.createCollection(coll.getName(), {collation: {locale: "en_US", strength: 2}}));
+ testDb.createCollection(coll.getName(), {collation: {locale: "en_US", strength: 2}}));
assert.commandWorked(coll.insert({_id: 1, str: "foo"}));
assert.eq({_id: 1, str: "foo"}, coll.findAndModify({query: {str: "FOO"}, update: {$set: {x: 1}}}));
@@ -996,10 +998,10 @@ assert.eq({_id: 1, str: "foo", x: 4}, coll.findAndModify({query: {str: "FOO"}, r
// findAndModify should return correct results when "simple" collation specified and collection
// has a default collation.
-coll = db.collation_findmodify5;
+coll = testDb.collation_findmodify5;
coll.drop();
assert.commandWorked(
- db.createCollection(coll.getName(), {collation: {locale: "en_US", strength: 2}}));
+ testDb.createCollection(coll.getName(), {collation: {locale: "en_US", strength: 2}}));
assert.commandWorked(coll.insert({_id: 1, str: "foo"}));
assert.eq(null,
coll.findAndModify(
@@ -1012,7 +1014,7 @@ assert.eq(null,
//
// mapReduce should return correct results when collation specified and no indexes exist.
-coll = db.collation_mapreduce1;
+coll = testDb.collation_mapreduce1;
coll.drop();
assert.commandWorked(coll.insert({_id: 1, str: "foo"}));
assert.commandWorked(coll.insert({_id: 2, str: "bar"}));
@@ -1029,10 +1031,10 @@ assert.eq(mapReduceOut.results.length, 1);
// mapReduce should return correct results when no collation specified and collection has a
// default collation.
-coll = db.collation_mapreduce2;
+coll = testDb.collation_mapreduce2;
coll.drop();
assert.commandWorked(
- db.createCollection(coll.getName(), {collation: {locale: "en_US", strength: 2}}));
+ testDb.createCollection(coll.getName(), {collation: {locale: "en_US", strength: 2}}));
assert.commandWorked(coll.insert({_id: 1, str: "foo"}));
var mapReduceOut = coll.mapReduce(
function() {
@@ -1047,10 +1049,10 @@ assert.eq(mapReduceOut.results.length, 1);
// mapReduce should return correct results when "simple" collation specified and collection has
// a default collation.
-coll = db.collation_mapreduce3;
+coll = testDb.collation_mapreduce3;
coll.drop();
assert.commandWorked(
- db.createCollection(coll.getName(), {collation: {locale: "en_US", strength: 2}}));
+ testDb.createCollection(coll.getName(), {collation: {locale: "en_US", strength: 2}}));
assert.commandWorked(coll.insert({_id: 1, str: "foo"}));
var mapReduceOut = coll.mapReduce(
function() {
@@ -1068,12 +1070,12 @@ assert.eq(mapReduceOut.results.length, 0);
//
// Remove should succeed when collation specified and collection does not exist.
-coll = db.collation_remove1;
+coll = testDb.collation_remove1;
coll.drop();
assert.commandWorked(coll.remove({str: "foo"}, {justOne: true, collation: {locale: "fr"}}));
// Remove should return correct results when collation specified.
-coll = db.collation_remove2;
+coll = testDb.collation_remove2;
coll.drop();
assert.commandWorked(coll.insert({_id: 1, str: "foo"}));
assert.commandWorked(coll.insert({_id: 2, str: "foo"}));
@@ -1082,7 +1084,7 @@ assert.commandWorked(writeRes);
assert.eq(1, writeRes.nRemoved);
// Explain of remove should return correct results when collation specified.
-coll = db.collation_remove3;
+coll = testDb.collation_remove3;
coll.drop();
assert.commandWorked(coll.insert({_id: 1, str: "foo"}));
assert.commandWorked(coll.insert({_id: 2, str: "foo"}));
@@ -1095,10 +1097,10 @@ assert.eq(1, planStage.nWouldDelete);
// Remove should return correct results when no collation specified and collection has a default
// collation.
-coll = db.collation_remove4;
+coll = testDb.collation_remove4;
coll.drop();
assert.commandWorked(
- db.createCollection(coll.getName(), {collation: {locale: "en_US", strength: 2}}));
+ testDb.createCollection(coll.getName(), {collation: {locale: "en_US", strength: 2}}));
assert.commandWorked(coll.insert({_id: 1, str: "foo"}));
writeRes = coll.remove({str: "FOO"}, {justOne: true});
assert.commandWorked(writeRes);
@@ -1106,10 +1108,10 @@ assert.eq(1, writeRes.nRemoved);
// Remove with idhack should return correct results when no collation specified and collection
// has a default collation.
-coll = db.collation_remove5;
+coll = testDb.collation_remove5;
coll.drop();
assert.commandWorked(
- db.createCollection(coll.getName(), {collation: {locale: "en_US", strength: 2}}));
+ testDb.createCollection(coll.getName(), {collation: {locale: "en_US", strength: 2}}));
assert.commandWorked(coll.insert({_id: "foo"}));
writeRes = coll.remove({_id: "FOO"}, {justOne: true});
assert.commandWorked(writeRes);
@@ -1125,9 +1127,9 @@ assert.eq(1, writeRes.nRemoved);
if (!isClustered) {
// Remove on _id should use idhack stage when query inherits collection default collation.
- coll = db.collation_remove6;
+ coll = testDb.collation_remove6;
coll.drop();
- assert.commandWorked(db.createCollection(coll.getName(), {collation: {locale: "en_US"}}));
+ assert.commandWorked(testDb.createCollection(coll.getName(), {collation: {locale: "en_US"}}));
explainRes = coll.explain("executionStats").remove({_id: "foo"});
assert.commandWorked(explainRes);
planStage = getPlanStage(explainRes.executionStats.executionStages, "IDHACK");
@@ -1136,10 +1138,10 @@ if (!isClustered) {
// Remove should return correct results when "simple" collation specified and collection has
// a default collation.
-coll = db.collation_remove7;
+coll = testDb.collation_remove7;
coll.drop();
assert.commandWorked(
- db.createCollection(coll.getName(), {collation: {locale: "en_US", strength: 2}}));
+ testDb.createCollection(coll.getName(), {collation: {locale: "en_US", strength: 2}}));
assert.commandWorked(coll.insert({_id: 1, str: "foo"}));
writeRes = coll.remove({str: "FOO"}, {justOne: true, collation: {locale: "simple"}});
assert.commandWorked(writeRes);
@@ -1147,10 +1149,10 @@ assert.eq(0, writeRes.nRemoved);
// Remove on _id should return correct results when "simple" collation specified and
// collection has a default collation.
-coll = db.collation_remove8;
+coll = testDb.collation_remove8;
coll.drop();
assert.commandWorked(
- db.createCollection(coll.getName(), {collation: {locale: "en_US", strength: 2}}));
+ testDb.createCollection(coll.getName(), {collation: {locale: "en_US", strength: 2}}));
assert.commandWorked(coll.insert({_id: "foo"}));
writeRes = coll.remove({_id: "FOO"}, {justOne: true, collation: {locale: "simple"}});
assert.commandWorked(writeRes);
@@ -1159,9 +1161,9 @@ assert.eq(0, writeRes.nRemoved);
if (!isClustered) {
// Remove on _id should use idhack stage when explicit query collation matches collection
// default.
- coll = db.collation_remove9;
+ coll = testDb.collation_remove9;
coll.drop();
- assert.commandWorked(db.createCollection(coll.getName(), {collation: {locale: "en_US"}}));
+ assert.commandWorked(testDb.createCollection(coll.getName(), {collation: {locale: "en_US"}}));
explainRes =
coll.explain("executionStats").remove({_id: "foo"}, {collation: {locale: "en_US"}});
assert.commandWorked(explainRes);
@@ -1170,9 +1172,9 @@ if (!isClustered) {
// Remove on _id should not use idhack stage when query collation does not match collection
// default.
- coll = db.collation_remove10;
+ coll = testDb.collation_remove10;
coll.drop();
- assert.commandWorked(db.createCollection(coll.getName(), {collation: {locale: "en_US"}}));
+ assert.commandWorked(testDb.createCollection(coll.getName(), {collation: {locale: "en_US"}}));
explainRes =
coll.explain("executionStats").remove({_id: "foo"}, {collation: {locale: "fr_CA"}});
assert.commandWorked(explainRes);
@@ -1185,13 +1187,13 @@ if (!isClustered) {
//
// Update should succeed when collation specified and collection does not exist.
-coll = db.collation_update1;
+coll = testDb.collation_update1;
coll.drop();
assert.commandWorked(
coll.update({str: "foo"}, {$set: {other: 99}}, {multi: true, collation: {locale: "fr"}}));
// Update should return correct results when collation specified.
-coll = db.collation_update2;
+coll = testDb.collation_update2;
coll.drop();
assert.commandWorked(coll.insert({_id: 1, str: "foo"}));
assert.commandWorked(coll.insert({_id: 2, str: "foo"}));
@@ -1200,7 +1202,7 @@ writeRes = coll.update(
assert.eq(2, writeRes.nModified);
// Explain of update should return correct results when collation specified.
-coll = db.collation_update3;
+coll = testDb.collation_update3;
coll.drop();
assert.commandWorked(coll.insert({_id: 1, str: "foo"}));
assert.commandWorked(coll.insert({_id: 2, str: "foo"}));
@@ -1215,10 +1217,10 @@ assert.eq(2, planStage.nWouldModify);
// Update should return correct results when no collation specified and collection has a default
// collation.
-coll = db.collation_update4;
+coll = testDb.collation_update4;
coll.drop();
assert.commandWorked(
- db.createCollection(coll.getName(), {collation: {locale: "en_US", strength: 2}}));
+ testDb.createCollection(coll.getName(), {collation: {locale: "en_US", strength: 2}}));
assert.commandWorked(coll.insert({_id: 1, str: "foo"}));
writeRes = coll.update({str: "FOO"}, {$set: {other: 99}});
assert.commandWorked(writeRes);
@@ -1226,10 +1228,10 @@ assert.eq(1, writeRes.nMatched);
// Update with idhack should return correct results when no collation specified and collection
// has a default collation.
-coll = db.collation_update5;
+coll = testDb.collation_update5;
coll.drop();
assert.commandWorked(
- db.createCollection(coll.getName(), {collation: {locale: "en_US", strength: 2}}));
+ testDb.createCollection(coll.getName(), {collation: {locale: "en_US", strength: 2}}));
assert.commandWorked(coll.insert({_id: "foo"}));
writeRes = coll.update({_id: "FOO"}, {$set: {other: 99}});
assert.commandWorked(writeRes);
@@ -1237,9 +1239,9 @@ assert.eq(1, writeRes.nMatched);
if (!isClustered) {
// Update on _id should use idhack stage when query inherits collection default collation.
- coll = db.collation_update6;
+ coll = testDb.collation_update6;
coll.drop();
- assert.commandWorked(db.createCollection(coll.getName(), {collation: {locale: "en_US"}}));
+ assert.commandWorked(testDb.createCollection(coll.getName(), {collation: {locale: "en_US"}}));
explainRes = coll.explain("executionStats").update({_id: "foo"}, {$set: {other: 99}});
assert.commandWorked(explainRes);
planStage = getPlanStage(explainRes.executionStats.executionStages, "IDHACK");
@@ -1248,10 +1250,10 @@ if (!isClustered) {
// Update should return correct results when "simple" collation specified and collection has
// a default collation.
-coll = db.collation_update7;
+coll = testDb.collation_update7;
coll.drop();
assert.commandWorked(
- db.createCollection(coll.getName(), {collation: {locale: "en_US", strength: 2}}));
+ testDb.createCollection(coll.getName(), {collation: {locale: "en_US", strength: 2}}));
assert.commandWorked(coll.insert({_id: 1, str: "foo"}));
writeRes = coll.update({str: "FOO"}, {$set: {other: 99}}, {collation: {locale: "simple"}});
assert.commandWorked(writeRes);
@@ -1259,10 +1261,10 @@ assert.eq(0, writeRes.nModified);
// Update on _id should return correct results when "simple" collation specified and
// collection has a default collation.
-coll = db.collation_update8;
+coll = testDb.collation_update8;
coll.drop();
assert.commandWorked(
- db.createCollection(coll.getName(), {collation: {locale: "en_US", strength: 2}}));
+ testDb.createCollection(coll.getName(), {collation: {locale: "en_US", strength: 2}}));
assert.commandWorked(coll.insert({_id: "foo"}));
writeRes = coll.update({_id: "FOO"}, {$set: {other: 99}}, {collation: {locale: "simple"}});
assert.commandWorked(writeRes);
@@ -1271,9 +1273,9 @@ assert.eq(0, writeRes.nModified);
if (!isClustered) {
// Update on _id should use idhack stage when explicitly given query collation matches
// collection default.
- coll = db.collation_update9;
+ coll = testDb.collation_update9;
coll.drop();
- assert.commandWorked(db.createCollection(coll.getName(), {collation: {locale: "en_US"}}));
+ assert.commandWorked(testDb.createCollection(coll.getName(), {collation: {locale: "en_US"}}));
explainRes = coll.explain("executionStats").update({_id: "foo"}, {$set: {other: 99}}, {
collation: {locale: "en_US"}
});
@@ -1283,9 +1285,9 @@ if (!isClustered) {
// Update on _id should not use idhack stage when query collation does not match collection
// default.
- coll = db.collation_update10;
+ coll = testDb.collation_update10;
coll.drop();
- assert.commandWorked(db.createCollection(coll.getName(), {collation: {locale: "en_US"}}));
+ assert.commandWorked(testDb.createCollection(coll.getName(), {collation: {locale: "en_US"}}));
explainRes = coll.explain("executionStats").update({_id: "foo"}, {$set: {other: 99}}, {
collation: {locale: "fr_CA"}
});
@@ -1299,9 +1301,9 @@ if (!isClustered) {
//
// $geoNear should fail when collation is specified but the collection does not exist.
-coll = db.collation_geonear1;
+coll = testDb.collation_geonear1;
coll.drop();
-assert.commandFailedWithCode(db.runCommand({
+assert.commandFailedWithCode(testDb.runCommand({
aggregate: coll.getName(),
cursor: {},
pipeline: [{
@@ -1315,10 +1317,10 @@ assert.commandFailedWithCode(db.runCommand({
ErrorCodes.NamespaceNotFound);
// $geoNear rejects the now-deprecated "collation" option.
-coll = db.collation_geonear2;
+coll = testDb.collation_geonear2;
coll.drop();
assert.commandWorked(coll.insert({geo: {type: "Point", coordinates: [0, 0]}, str: "abc"}));
-assert.commandFailedWithCode(db.runCommand({
+assert.commandFailedWithCode(testDb.runCommand({
aggregate: coll.getName(),
cursor: {},
pipeline: [{
@@ -1371,20 +1373,20 @@ assert.eq(1, coll.aggregate([geoNearStage], {collation: {locale: "en_US", streng
// $geoNear should return correct results when no collation specified and collection has a
// default collation.
-coll = db.collation_geonear3;
+coll = testDb.collation_geonear3;
coll.drop();
assert.commandWorked(
- db.createCollection(coll.getName(), {collation: {locale: "en_US", strength: 2}}));
+ testDb.createCollection(coll.getName(), {collation: {locale: "en_US", strength: 2}}));
assert.commandWorked(coll.createIndex({geo: "2dsphere"}));
assert.commandWorked(coll.insert({geo: {type: "Point", coordinates: [0, 0]}, str: "abc"}));
assert.eq(1, coll.aggregate([geoNearStage]).itcount());
// $geoNear should return correct results when "simple" collation specified and collection has
// a default collation.
-coll = db.collation_geonear4;
+coll = testDb.collation_geonear4;
coll.drop();
assert.commandWorked(
- db.createCollection(coll.getName(), {collation: {locale: "en_US", strength: 2}}));
+ testDb.createCollection(coll.getName(), {collation: {locale: "en_US", strength: 2}}));
assert.commandWorked(coll.createIndex({geo: "2dsphere"}));
assert.commandWorked(coll.insert({geo: {type: "Point", coordinates: [0, 0]}, str: "abc"}));
assert.eq(0, coll.aggregate([geoNearStage], {collation: {locale: "simple"}}).itcount());
@@ -1395,7 +1397,7 @@ assert.eq(0, coll.aggregate([geoNearStage], {collation: {locale: "simple"}}).itc
// Find with $nearSphere should return correct results when collation specified and
// collection does not exist.
-coll = db.collation_nearsphere1;
+coll = testDb.collation_nearsphere1;
coll.drop();
assert.eq(
0,
@@ -1405,7 +1407,7 @@ assert.eq(
// Find with $nearSphere should return correct results when collation specified and string
// predicate not indexed.
-coll = db.collation_nearsphere2;
+coll = testDb.collation_nearsphere2;
coll.drop();
assert.commandWorked(coll.insert({geo: {type: "Point", coordinates: [0, 0]}, str: "abc"}));
assert.commandWorked(coll.createIndex({geo: "2dsphere"}));
@@ -1470,7 +1472,7 @@ assert.eq(
var bulk;
// update().
-coll = db.collation_bulkupdate;
+coll = testDb.collation_bulkupdate;
coll.drop();
assert.commandWorked(coll.insert({_id: 1, str: "foo"}));
assert.commandWorked(coll.insert({_id: 2, str: "foo"}));
@@ -1481,7 +1483,7 @@ assert.commandWorked(writeRes);
assert.eq(2, writeRes.nModified);
// updateOne().
-coll = db.collation_bulkupdateone;
+coll = testDb.collation_bulkupdateone;
coll.drop();
assert.commandWorked(coll.insert({_id: 1, str: "foo"}));
assert.commandWorked(coll.insert({_id: 2, str: "foo"}));
@@ -1492,7 +1494,7 @@ assert.commandWorked(writeRes);
assert.eq(1, writeRes.nModified);
// replaceOne().
-coll = db.collation_bulkreplaceone1;
+coll = testDb.collation_bulkreplaceone1;
coll.drop();
assert.commandWorked(coll.insert({_id: 1, str: "foo"}));
assert.commandWorked(coll.insert({_id: 2, str: "foo"}));
@@ -1503,7 +1505,7 @@ assert.commandWorked(writeRes);
assert.eq(1, writeRes.nModified);
// replaceOne() with upsert().
-coll = db.collation_bulkreplaceone2;
+coll = testDb.collation_bulkreplaceone2;
coll.drop();
assert.commandWorked(coll.insert({_id: 1, str: "foo"}));
assert.commandWorked(coll.insert({_id: 2, str: "foo"}));
@@ -1522,7 +1524,7 @@ assert.eq(0, writeRes.nUpserted);
assert.eq(1, writeRes.nModified);
// removeOne().
-coll = db.collation_bulkremoveone;
+coll = testDb.collation_bulkremoveone;
coll.drop();
assert.commandWorked(coll.insert({_id: 1, str: "foo"}));
assert.commandWorked(coll.insert({_id: 2, str: "foo"}));
@@ -1533,7 +1535,7 @@ assert.commandWorked(writeRes);
assert.eq(1, writeRes.nRemoved);
// remove().
-coll = db.collation_bulkremove;
+coll = testDb.collation_bulkremove;
coll.drop();
assert.commandWorked(coll.insert({_id: 1, str: "foo"}));
assert.commandWorked(coll.insert({_id: 2, str: "foo"}));
@@ -1548,7 +1550,7 @@ assert.eq(2, writeRes.nRemoved);
//
// deleteOne().
-coll = db.collation_deleteone;
+coll = testDb.collation_deleteone;
coll.drop();
assert.commandWorked(coll.insert({_id: 1, str: "foo"}));
assert.commandWorked(coll.insert({_id: 2, str: "foo"}));
@@ -1556,7 +1558,7 @@ res = coll.deleteOne({str: "FOO"}, {collation: {locale: "en_US", strength: 2}});
assert.eq(1, res.deletedCount);
// deleteMany().
-coll = db.collation_deletemany;
+coll = testDb.collation_deletemany;
coll.drop();
assert.commandWorked(coll.insert({_id: 1, str: "foo"}));
assert.commandWorked(coll.insert({_id: 2, str: "foo"}));
@@ -1564,7 +1566,7 @@ res = coll.deleteMany({str: "FOO"}, {collation: {locale: "en_US", strength: 2}})
assert.eq(2, res.deletedCount);
// findOneAndDelete().
-coll = db.collation_findonedelete;
+coll = testDb.collation_findonedelete;
coll.drop();
assert.commandWorked(coll.insert({_id: 1, str: "foo"}));
assert.eq({_id: 1, str: "foo"},
@@ -1572,7 +1574,7 @@ assert.eq({_id: 1, str: "foo"},
assert.eq(null, coll.findOne({_id: 1}));
// findOneAndReplace().
-coll = db.collation_findonereplace;
+coll = testDb.collation_findonereplace;
coll.drop();
assert.commandWorked(coll.insert({_id: 1, str: "foo"}));
assert.eq({_id: 1, str: "foo"},
@@ -1581,7 +1583,7 @@ assert.eq({_id: 1, str: "foo"},
assert.neq(null, coll.findOne({str: "bar"}));
// findOneAndUpdate().
-coll = db.collation_findoneupdate;
+coll = testDb.collation_findoneupdate;
coll.drop();
assert.commandWorked(coll.insert({_id: 1, str: "foo"}));
assert.eq({_id: 1, str: "foo"},
@@ -1590,7 +1592,7 @@ assert.eq({_id: 1, str: "foo"},
assert.neq(null, coll.findOne({other: 99}));
// replaceOne().
-coll = db.collation_replaceone;
+coll = testDb.collation_replaceone;
coll.drop();
assert.commandWorked(coll.insert({_id: 1, str: "foo"}));
assert.commandWorked(coll.insert({_id: 2, str: "foo"}));
@@ -1598,7 +1600,7 @@ res = coll.replaceOne({str: "FOO"}, {str: "bar"}, {collation: {locale: "en_US",
assert.eq(1, res.modifiedCount);
// updateOne().
-coll = db.collation_updateone;
+coll = testDb.collation_updateone;
coll.drop();
assert.commandWorked(coll.insert({_id: 1, str: "foo"}));
assert.commandWorked(coll.insert({_id: 2, str: "foo"}));
@@ -1607,7 +1609,7 @@ res =
assert.eq(1, res.modifiedCount);
// updateMany().
-coll = db.collation_updatemany;
+coll = testDb.collation_updatemany;
coll.drop();
assert.commandWorked(coll.insert({_id: 1, str: "foo"}));
assert.commandWorked(coll.insert({_id: 2, str: "foo"}));
@@ -1616,7 +1618,7 @@ res =
assert.eq(2, res.modifiedCount);
// updateOne with bulkWrite().
-coll = db.collation_updateonebulkwrite;
+coll = testDb.collation_updateonebulkwrite;
coll.drop();
assert.commandWorked(coll.insert({_id: 1, str: "foo"}));
assert.commandWorked(coll.insert({_id: 2, str: "foo"}));
@@ -1643,7 +1645,7 @@ for (let backwards of [undefined, null]) {
}
// updateMany with bulkWrite().
-coll = db.collation_updatemanybulkwrite;
+coll = testDb.collation_updatemanybulkwrite;
coll.drop();
assert.commandWorked(coll.insert({_id: 1, str: "foo"}));
assert.commandWorked(coll.insert({_id: 2, str: "foo"}));
@@ -1657,7 +1659,7 @@ res = coll.bulkWrite([{
assert.eq(2, res.matchedCount);
// replaceOne with bulkWrite().
-coll = db.collation_replaceonebulkwrite;
+coll = testDb.collation_replaceonebulkwrite;
coll.drop();
assert.commandWorked(coll.insert({_id: 1, str: "foo"}));
assert.commandWorked(coll.insert({_id: 2, str: "foo"}));
@@ -1668,7 +1670,7 @@ res = coll.bulkWrite([{
assert.eq(1, res.matchedCount);
// deleteOne with bulkWrite().
-coll = db.collation_deleteonebulkwrite;
+coll = testDb.collation_deleteonebulkwrite;
coll.drop();
assert.commandWorked(coll.insert({_id: 1, str: "foo"}));
assert.commandWorked(coll.insert({_id: 2, str: "foo"}));
@@ -1677,7 +1679,7 @@ res = coll.bulkWrite(
assert.eq(1, res.deletedCount);
// deleteMany with bulkWrite().
-coll = db.collation_deletemanybulkwrite;
+coll = testDb.collation_deletemanybulkwrite;
coll.drop();
assert.commandWorked(coll.insert({_id: 1, str: "foo"}));
assert.commandWorked(coll.insert({_id: 2, str: "foo"}));
@@ -1686,7 +1688,7 @@ res = coll.bulkWrite(
assert.eq(2, res.deletedCount);
// Two deleteOne ops with bulkWrite using different collations.
-coll = db.collation_deleteone2collation;
+coll = testDb.collation_deleteone2collation;
coll.drop();
assert.commandWorked(coll.insert({_id: 1, str: "foo"}));
assert.commandWorked(coll.insert({_id: 2, str: "bar"}));
@@ -1698,14 +1700,14 @@ assert.eq(2, res.deletedCount);
// applyOps.
if (!isMongos) {
- coll = db.collation_applyops;
+ coll = testDb.collation_applyops;
coll.drop();
assert.commandWorked(
- db.createCollection(coll.getName(), {collation: {locale: "en_US", strength: 2}}));
+ testDb.createCollection(coll.getName(), {collation: {locale: "en_US", strength: 2}}));
assert.commandWorked(coll.insert({_id: "foo", x: 5, str: "bar"}));
// <operation>.o2 respects collection default collation.
- assert.commandWorked(db.runCommand({
+ assert.commandWorked(testDb.runCommand({
applyOps:
[{op: "u", ns: coll.getFullName(), o2: {_id: "FOO"}, o: {$v: 2, diff: {u: {x: 6}}}}]
}));
@@ -1716,16 +1718,16 @@ if (!isMongos) {
// default collation of the corresponding collection. We skip running this command in a sharded
// cluster because it isn't supported by mongos.
if (!isMongos) {
- const clonedColl = db.collation_cloned;
+ const clonedColl = testDb.collation_cloned;
- coll = db.collation_orig;
+ coll = testDb.collation_orig;
coll.drop();
clonedColl.drop();
// Create a collection with a non-simple default collation.
assert.commandWorked(
- db.runCommand({create: coll.getName(), collation: {locale: "en", strength: 2}}));
- const originalCollectionInfos = db.getCollectionInfos({name: coll.getName()});
+ testDb.runCommand({create: coll.getName(), collation: {locale: "en", strength: 2}}));
+ const originalCollectionInfos = testDb.getCollectionInfos({name: coll.getName()});
assert.eq(originalCollectionInfos.length, 1, tojson(originalCollectionInfos));
assert.commandWorked(coll.insert({_id: "FOO"}));
@@ -1734,10 +1736,10 @@ if (!isMongos) {
coll.find({_id: "foo"}).toArray(),
"query should have performed a case-insensitive match");
- var cloneCollOutput = db.runCommand(
+ var cloneCollOutput = testDb.runCommand(
{cloneCollectionAsCapped: coll.getName(), toCollection: clonedColl.getName(), size: 4096});
assert.commandWorked(cloneCollOutput);
- const clonedCollectionInfos = db.getCollectionInfos({name: clonedColl.getName()});
+ const clonedCollectionInfos = testDb.getCollectionInfos({name: clonedColl.getName()});
assert.eq(clonedCollectionInfos.length, 1, tojson(clonedCollectionInfos));
assert.eq(originalCollectionInfos[0].options.collation,
clonedCollectionInfos[0].options.collation);
@@ -1745,7 +1747,7 @@ if (!isMongos) {
}
// Test that the find command's min/max options respect the collation.
-coll = db.collation_minmax1;
+coll = testDb.collation_minmax1;
coll.drop();
assert.commandWorked(coll.insert({str: "a"}));
assert.commandWorked(coll.insert({str: "A"}));
@@ -1806,7 +1808,7 @@ assert.eq(4,
.itcount());
// Ensure results from index with min/max query are sorted to match requested collation.
-coll = db.collation_minmax2;
+coll = testDb.collation_minmax2;
coll.drop();
assert.commandWorked(coll.createIndex({a: 1, b: 1}));
assert.commandWorked(
@@ -1841,7 +1843,7 @@ explainRes = coll.find({}, {_id: 0})
.sort({a: 1, b: 1})
.explain();
assert.commandWorked(explainRes);
-assert(planHasStage(db, getWinningPlan(explainRes.queryPlanner), "SORT"));
+assert(planHasStage(testDb, getWinningPlan(explainRes.queryPlanner), "SORT"));
// This query should fail since min has a string as one of it's boundaries, and the
// collation doesn't match that of the index.