summaryrefslogtreecommitdiff
path: root/jstests/core/collation.js
diff options
context:
space:
mode:
authorLucas de Castro Borges <lucas@gnuabordo.com.br>2025-02-11 15:07:35 -0300
committerLucas de Castro Borges <lucas@gnuabordo.com.br>2025-02-11 15:07:35 -0300
commit4cb8841196d0625dfa3825aa326f071cd27c7b8b (patch)
tree1682a647d4463397c119183369ae6f750d5fdcff /jstests/core/collation.js
parentaa03c6362cbaa767638e6eed9b031d86dd2643d1 (diff)
parent8f0827553e09872941945a093b647a4211a9db7f (diff)
Update upstream source from tag 'upstream/6.0.0'master
Update to upstream version '6.0.0' with Debian dir 5604a80ec1c96ca76f25f40d78e6ef855abec322
Diffstat (limited to 'jstests/core/collation.js')
-rw-r--r--jstests/core/collation.js314
1 files changed, 102 insertions, 212 deletions
diff --git a/jstests/core/collation.js b/jstests/core/collation.js
index 558d1af428c..6a7ff93c9c7 100644
--- a/jstests/core/collation.js
+++ b/jstests/core/collation.js
@@ -24,19 +24,18 @@ load("jstests/libs/sbe_explain_helpers.js"); // For engineSpecificAssertion.
// For areAllCollectionsClustered.
load("jstests/libs/clustered_collections/clustered_collection_util.js");
-let testDb = db.getSiblingDB("collation_js");
-var coll = testDb.collation;
+var coll = db.collation;
coll.drop();
var explainRes;
var writeRes;
var planStage;
-var hello = testDb.runCommand("hello");
+var hello = db.runCommand("hello");
assert.commandWorked(hello);
var isMongos = (hello.msg === "isdbgrid");
var isStandalone = !isMongos && !hello.hasOwnProperty('setName');
-var isClustered = ClusteredCollectionUtil.areAllCollectionsClustered(testDb);
+var isClustered = ClusteredCollectionUtil.areAllCollectionsClustered(db);
var assertIndexHasCollation = function(keyPattern, collation) {
var indexSpecs = coll.getIndexes();
@@ -62,38 +61,35 @@ var getQueryCollation = function(explainRes) {
};
//
-// Test using testDb.createCollection() to make a collection with a default collation.
+// Test using db.createCollection() to make a collection with a default collation.
//
// Attempting to create a collection with an invalid collation should fail.
-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}}));
+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}}));
// 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(
- testDb.createCollection("collation", {collation: {locale: "en", version: "unknownVersion"}}),
+ db.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(testDb.createCollection(coll.getName(), {collation: {locale: "simple"}}));
-var collectionInfos = testDb.getCollectionInfos({name: coll.getName()});
+assert.commandWorked(db.createCollection("collation", {collation: {locale: "simple"}}));
+var collectionInfos = db.getCollectionInfos({name: "collation"});
assert.eq(collectionInfos.length, 1);
assert(!collectionInfos[0].options.hasOwnProperty("collation"));
+coll.drop();
// Ensure that we populate all collation-related fields when we create a collection with a valid
// collation.
-coll = testDb.collation_frCA;
-coll.drop();
-assert.commandWorked(testDb.createCollection(coll.getName(), {collation: {locale: "fr_CA"}}));
-var collectionInfos = testDb.getCollectionInfos({name: coll.getName()});
+assert.commandWorked(db.createCollection("collation", {collation: {locale: "fr_CA"}}));
+var collectionInfos = db.getCollectionInfos({name: "collation"});
assert.eq(collectionInfos.length, 1);
assert.eq(collectionInfos[0].options.collation, {
locale: "fr_CA",
@@ -180,8 +176,8 @@ if (isStandalone) {
assertIndexHasCollation({c: 1}, {locale: "simple"});
}
-coll = testDb.collation_index1;
coll.drop();
+
//
// Creating an index with a collation.
//
@@ -259,7 +255,6 @@ 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 = testDb.collation_index2;
coll.drop();
assert.commandWorked(coll.createIndex({a: 1}, {collation: {locale: "fr_CA"}}));
assert.commandWorked(coll.createIndex({b: 1}));
@@ -271,41 +266,37 @@ 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 = 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(testDb, getWinningPlan(explainRes.queryPlanner), "COLLSCAN"));
+assert(planHasStage(db, 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(testDb, getWinningPlan(explainRes.queryPlanner), "COLLSCAN"));
+assert(planHasStage(db, getWinningPlan(explainRes.queryPlanner), "COLLSCAN"));
// Matching collations.
explainRes = coll.find({a: "foo"}).collation({locale: "fr_CA"}).explain();
assert.commandWorked(explainRes);
-assert(planHasStage(testDb, getWinningPlan(explainRes.queryPlanner), "IXSCAN"));
+assert(planHasStage(db, getWinningPlan(explainRes.queryPlanner), "IXSCAN"));
// Should not be possible to create a text index with an explicit non-simple collation.
-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 = testDb.collation_en1;
coll.drop();
-assert.commandWorked(testDb.createCollection(coll.getName(), {collation: {locale: "en"}}));
+assert.commandWorked(db.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 = testDb.collation_en2;
coll.drop();
-assert.commandWorked(testDb.createCollection(coll.getName(), {collation: {locale: "en"}}));
+assert.commandWorked(db.createCollection(coll.getName(), {collation: {locale: "en"}}));
assert.commandWorked(coll.createIndex({a: "text"}, {collation: {locale: "simple"}}));
//
@@ -314,12 +305,10 @@ assert.commandWorked(coll.createIndex({a: "text"}, {collation: {locale: "simple"
// Aggregation should return correct results when collation specified and collection does not
// exist.
-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 = testDb.collation_agg2;
coll.drop();
assert.commandWorked(coll.insert({_id: 1, str: "foo"}));
assert.commandWorked(coll.insert({_id: 2, str: "bar"}));
@@ -330,39 +319,35 @@ assert.eq(1,
// Aggregation should return correct results when no collation specified and collection has a
// default collation.
-coll = testDb.collation_agg3;
coll.drop();
assert.commandWorked(
- testDb.createCollection(coll.getName(), {collation: {locale: "en_US", strength: 2}}));
+ db.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 = testDb.collation_agg4;
coll.drop();
assert.commandWorked(
- testDb.createCollection(coll.getName(), {collation: {locale: "en_US", strength: 2}}));
+ db.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 = testDb.collation_agg5;
coll.drop();
-assert.commandWorked(testDb.createCollection(coll.getName(), {collation: {locale: "en_US"}}));
+assert.commandWorked(db.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(testDb, getWinningPlan(explain.queryPlanner)));
+assert(isIxscan(db, getWinningPlan(explain.queryPlanner)));
// Aggregation should not use index when no collation specified and collection default
// collation is incompatible with index collation.
-coll = testDb.collation_agg6;
coll.drop();
-assert.commandWorked(testDb.createCollection(coll.getName(), {collation: {locale: "en_US"}}));
+assert.commandWorked(db.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(testDb, getWinningPlan(explain.queryPlanner)));
+assert(isCollscan(db, getWinningPlan(explain.queryPlanner)));
// Explain of aggregation with collation should succeed.
assert.commandWorked(coll.explain().aggregate([], {collation: {locale: "fr"}}));
@@ -372,12 +357,10 @@ assert.commandWorked(coll.explain().aggregate([], {collation: {locale: "fr"}}));
//
// Count should return correct results when collation specified and collection does not exist.
-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 = testDb.collation_count1;
coll.drop();
assert.commandWorked(coll.insert({_id: 1, str: "foo"}));
assert.commandWorked(coll.insert({_id: 2, str: "bar"}));
@@ -390,24 +373,21 @@ 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 = testDb.collation_count3;
coll.drop();
assert.commandWorked(
- testDb.createCollection(coll.getName(), {collation: {locale: "en_US", strength: 2}}));
+ db.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 = testDb.collation_count4;
coll.drop();
assert.commandWorked(
- testDb.createCollection(coll.getName(), {collation: {locale: "en_US", strength: 2}}));
+ db.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 = testDb.collation_count5;
coll.drop();
assert.commandWorked(coll.insert({_id: 1, str: "foo"}));
assert.commandWorked(coll.insert({_id: 2, str: "bar"}));
@@ -426,7 +406,6 @@ assert.neq(null, planStage);
assert.eq(1, planStage.advanced);
// Explain of COUNT_SCAN stage should include index collation.
-coll = testDb.collation_count6;
coll.drop();
assert.commandWorked(coll.createIndex({a: 1}, {collation: {locale: "fr_CA"}}));
explainRes = coll.explain("executionStats").find({a: 5}).count();
@@ -448,9 +427,8 @@ assert.eq(planStage.collation, {
// Explain of COUNT_SCAN stage should include index collation when index collation is
// inherited from collection default.
-coll = testDb.collation_count7;
coll.drop();
-assert.commandWorked(testDb.createCollection(coll.getName(), {collation: {locale: "fr_CA"}}));
+assert.commandWorked(db.createCollection(coll.getName(), {collation: {locale: "fr_CA"}}));
assert.commandWorked(coll.createIndex({a: 1}));
explainRes = coll.explain("executionStats").find({a: 5}).count();
assert.commandWorked(explainRes);
@@ -470,14 +448,13 @@ assert.eq(planStage.collation, {
});
// Should be able to use COUNT_SCAN for queries over strings.
-coll = testDb.collation_count8;
coll.drop();
-assert.commandWorked(testDb.createCollection(coll.getName(), {collation: {locale: "fr_CA"}}));
+assert.commandWorked(db.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(testDb, explainRes.executionStats.executionStages, "COUNT_SCAN"));
-assert(!planHasStage(testDb, explainRes.executionStats.executionStages, "FETCH"));
+assert(planHasStage(db, explainRes.executionStats.executionStages, "COUNT_SCAN"));
+assert(!planHasStage(db, explainRes.executionStats.executionStages, "FETCH"));
//
// Collation tests for distinct.
@@ -485,12 +462,10 @@ assert(!planHasStage(testDb, explainRes.executionStats.executionStages, "FETCH")
// Distinct should return correct results when collation specified and collection does not
// exist.
-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 = testDb.collation_distinct2;
coll.drop();
assert.commandWorked(coll.insert({_id: 1, str: "foo"}));
assert.commandWorked(coll.insert({_id: 2, str: "FOO"}));
@@ -510,10 +485,9 @@ 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 = testDb.collation_distinct3;
coll.drop();
assert.commandWorked(
- testDb.createCollection(coll.getName(), {collation: {locale: "en_US", strength: 2}}));
+ db.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);
@@ -521,10 +495,9 @@ 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 = testDb.collation_distinct4;
coll.drop();
assert.commandWorked(
- testDb.createCollection(coll.getName(), {collation: {locale: "en_US", strength: 2}}));
+ db.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);
@@ -532,45 +505,42 @@ 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 = testDb.collation_distinct5;
coll.drop();
-assert.commandWorked(testDb.createCollection(coll.getName(), {collation: {locale: "en_US"}}));
+assert.commandWorked(db.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(testDb, getWinningPlan(explain.queryPlanner), "DISTINCT_SCAN"));
-assert(planHasStage(testDb, getWinningPlan(explain.queryPlanner), "FETCH"));
+assert(planHasStage(db, getWinningPlan(explain.queryPlanner), "DISTINCT_SCAN"));
+assert(planHasStage(db, 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(testDb, getWinningPlan(explain.queryPlanner), "DISTINCT_SCAN"));
-assert(planHasStage(testDb, getWinningPlan(explain.queryPlanner), "FETCH"));
-assert(!planHasStage(testDb, getWinningPlan(explain.queryPlanner), "PROJECTION_COVERED"));
+assert(planHasStage(db, getWinningPlan(explain.queryPlanner), "DISTINCT_SCAN"));
+assert(planHasStage(db, getWinningPlan(explain.queryPlanner), "FETCH"));
+assert(!planHasStage(db, 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(testDb, getWinningPlan(explain.queryPlanner), "IXSCAN"));
-assert(planHasStage(testDb, getWinningPlan(explain.queryPlanner), "FETCH"));
-assert(!planHasStage(testDb, getWinningPlan(explain.queryPlanner), "DISTINCT_SCAN"));
+assert(planHasStage(db, getWinningPlan(explain.queryPlanner), "IXSCAN"));
+assert(planHasStage(db, getWinningPlan(explain.queryPlanner), "FETCH"));
+assert(!planHasStage(db, 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(testDb, getWinningPlan(explain.queryPlanner), "DISTINCT_SCAN"));
-assert(planHasStage(testDb, getWinningPlan(explain.queryPlanner), "PROJECTION_COVERED"));
-assert(!planHasStage(testDb, getWinningPlan(explain.queryPlanner), "FETCH"));
+assert(planHasStage(db, getWinningPlan(explain.queryPlanner), "DISTINCT_SCAN"));
+assert(planHasStage(db, getWinningPlan(explain.queryPlanner), "PROJECTION_COVERED"));
+assert(!planHasStage(db, getWinningPlan(explain.queryPlanner), "FETCH"));
// Distinct should not use index when no collation specified and collection default collation is
// incompatible with index collation.
-coll = testDb.collation_distinct6;
coll.drop();
-assert.commandWorked(testDb.createCollection(coll.getName(), {collation: {locale: "en_US"}}));
+assert.commandWorked(db.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(testDb, getWinningPlan(explain.queryPlanner)));
+assert(isCollscan(db, getWinningPlan(explain.queryPlanner)));
// Explain of DISTINCT_SCAN stage should include index collation.
-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"}});
@@ -592,9 +562,8 @@ assert.eq(planStage.collation, {
// Explain of DISTINCT_SCAN stage should include index collation when index collation is
// inherited from collection default.
-coll = testDb.collation_distinct8;
coll.drop();
-assert.commandWorked(testDb.createCollection(coll.getName(), {collation: {locale: "fr_CA"}}));
+assert.commandWorked(db.createCollection(coll.getName(), {collation: {locale: "fr_CA"}}));
assert.commandWorked(coll.createIndex({str: 1}));
explainRes = coll.explain("executionStats").distinct("str");
assert.commandWorked(explainRes);
@@ -619,12 +588,10 @@ assert.eq(planStage.collation, {
// Find should return correct results when collation specified and collection does not
// exist.
-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 = testDb.collation_find2;
coll.drop();
assert.commandWorked(coll.insert({_id: 1, str: "foo"}));
assert.commandWorked(coll.insert({_id: 2, str: "bar"}));
@@ -668,7 +635,6 @@ assert.commandWorked(coll.dropIndexes());
// Queries that use a index with a non-matching collation should add a sort
// stage if needed.
-coll = testDb.collation_find3;
coll.drop();
assert.commandWorked(coll.insert([{a: "A"}, {a: "B"}, {a: "b"}, {a: "a"}]));
@@ -681,7 +647,6 @@ 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 = testDb.collation_find4;
coll.drop();
assert.commandWorked(coll.insert([{a: "A"}, {a: "B"}]));
assert.eq(
@@ -689,10 +654,9 @@ assert.eq(
// Find should return correct results when no collation specified and collection has a default
// collation.
-coll = testDb.collation_find5;
coll.drop();
assert.commandWorked(
- testDb.createCollection(coll.getName(), {collation: {locale: "en_US", strength: 2}}));
+ db.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"}));
@@ -704,28 +668,25 @@ 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 = testDb.collation_find6;
coll.drop();
assert.commandWorked(
- testDb.createCollection(coll.getName(), {collation: {locale: "en_US", strength: 2}}));
+ db.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 = testDb.collation_find7;
coll.drop();
assert.commandWorked(
- testDb.createCollection(coll.getName(), {collation: {locale: "en_US", strength: 2}}));
+ db.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 = testDb.collation_find8;
coll.drop();
assert.commandWorked(
- testDb.createCollection(coll.getName(), {collation: {locale: "en_US", strength: 2}}));
+ db.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"}));
@@ -736,30 +697,27 @@ assert.eq([{str: "FOO"}, {str: "bar"}, {str: "foo"}],
// Find on _id should return correct results when query collation differs from collection
// default collation.
-coll = testDb.collation_find9;
coll.drop();
assert.commandWorked(
- testDb.createCollection(coll.getName(), {collation: {locale: "en_US", strength: 3}}));
+ db.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 = testDb.collation_find10;
coll.drop();
- assert.commandWorked(testDb.createCollection(coll.getName(), {collation: {locale: "en_US"}}));
+ assert.commandWorked(db.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, testDb, explainRes);
+ engineSpecificAssertion(classicAssert, sbeAssert, db, explainRes);
// Find on _id should use idhack stage when explicitly given query collation matches
// collection default.
- coll = testDb.collation_find11;
coll.drop();
- assert.commandWorked(testDb.createCollection(coll.getName(), {collation: {locale: "en_US"}}));
+ assert.commandWorked(db.createCollection(coll.getName(), {collation: {locale: "en_US"}}));
explainRes =
coll.explain("executionStats").find({_id: "foo"}).collation({locale: "en_US"}).finish();
assert.commandWorked(explainRes);
@@ -769,9 +727,8 @@ if (!isClustered) {
// Find on _id should not use idhack stage when query collation does not match collection
// default.
- coll = testDb.collation_find12;
coll.drop();
- assert.commandWorked(testDb.createCollection(coll.getName(), {collation: {locale: "en_US"}}));
+ assert.commandWorked(db.createCollection(coll.getName(), {collation: {locale: "en_US"}}));
explainRes =
coll.explain("executionStats").find({_id: "foo"}).collation({locale: "fr_CA"}).finish();
assert.commandWorked(explainRes);
@@ -783,42 +740,37 @@ if (!isClustered) {
// Find should select compatible index when no collation specified and collection has a default
// collation.
-coll = testDb.collation_find13;
coll.drop();
-assert.commandWorked(testDb.createCollection(coll.getName(), {collation: {locale: "en_US"}}));
+assert.commandWorked(db.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(testDb, getWinningPlan(explain.queryPlanner)));
+assert(isIxscan(db, getWinningPlan(explain.queryPlanner)));
// Find should select compatible index when no collation specified and collection default
// collation is "simple".
-coll = testDb.collation_find14;
coll.drop();
-assert.commandWorked(testDb.createCollection(coll.getName(), {collation: {locale: "simple"}}));
+assert.commandWorked(db.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(testDb, getWinningPlan(explain.queryPlanner)));
+assert(isIxscan(db, 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 = testDb.collation_find15;
coll.drop();
-assert.commandWorked(testDb.createCollection(coll.getName(), {collation: {locale: "en_US"}}));
+assert.commandWorked(db.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(testDb, getWinningPlan(explain.queryPlanner)));
+assert(isCollscan(db, getWinningPlan(explain.queryPlanner)));
// Find should select compatible index when "simple" collation specified and collection has a
// non-"simple" default collation.
-coll = testDb.collation_find16;
coll.drop();
-assert.commandWorked(testDb.createCollection(coll.getName(), {collation: {locale: "en_US"}}));
+assert.commandWorked(db.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(testDb, getWinningPlan(explain.queryPlanner)));
+assert(isIxscan(db, getWinningPlan(explain.queryPlanner)));
// Find should return correct results when collation specified and run with explain.
-coll = testDb.collation_find17;
coll.drop();
assert.commandWorked(coll.insert({str: "foo"}));
explainRes =
@@ -833,7 +785,6 @@ assert.commandWorked(explainRes);
assert.eq(1, explainRes.executionStats.nReturned);
// Explain of find should include query collation.
-coll = testDb.collation_find18;
coll.drop();
explainRes =
coll.explain("executionStats").find({str: "foo"}).collation({locale: "fr_CA"}).finish();
@@ -852,9 +803,8 @@ assert.eq(getQueryCollation(explainRes), {
});
// Explain of find should include query collation when inherited from collection default.
-coll = testDb.collation_find19;
coll.drop();
-assert.commandWorked(testDb.createCollection(coll.getName(), {collation: {locale: "fr_CA"}}));
+assert.commandWorked(db.createCollection(coll.getName(), {collation: {locale: "fr_CA"}}));
explainRes = coll.explain("executionStats").find({str: "foo"}).finish();
assert.commandWorked(explainRes);
assert.eq(getQueryCollation(explainRes), {
@@ -871,7 +821,6 @@ assert.eq(getQueryCollation(explainRes), {
});
// Explain of IXSCAN stage should include index collation.
-coll = testDb.collation_find20;
coll.drop();
assert.commandWorked(coll.createIndex({str: 1}, {collation: {locale: "fr_CA"}}));
explainRes =
@@ -894,9 +843,8 @@ assert.eq(planStage.collation, {
// Explain of IXSCAN stage should include index collation when index collation is inherited from
// collection default.
-coll = testDb.collation_find21;
coll.drop();
-assert.commandWorked(testDb.createCollection(coll.getName(), {collation: {locale: "fr_CA"}}));
+assert.commandWorked(db.createCollection(coll.getName(), {collation: {locale: "fr_CA"}}));
assert.commandWorked(coll.createIndex({str: 1}));
explainRes = coll.explain("executionStats").find({str: "foo"}).finish();
assert.commandWorked(explainRes);
@@ -921,7 +869,6 @@ assert.eq(planStage.collation, {
// findAndModify should return correct results when collation specified and collection does not
// exist.
-coll = testDb.collation_findmodify1;
coll.drop();
assert.eq(
null,
@@ -929,7 +876,6 @@ assert.eq(
{query: {str: "bar"}, update: {$set: {str: "baz"}}, new: true, collation: {locale: "fr"}}));
// Update-findAndModify should return correct results when collation specified.
-coll = testDb.collation_findmodify2;
coll.drop();
assert.commandWorked(coll.insert({_id: 1, str: "foo"}));
assert.commandWorked(coll.insert({_id: 2, str: "bar"}));
@@ -953,7 +899,6 @@ assert.neq(null, planStage);
assert.eq(1, planStage.nWouldModify);
// Delete-findAndModify should return correct results when collation specified.
-coll = testDb.collation_findmodify3;
coll.drop();
assert.commandWorked(coll.insert({_id: 1, str: "foo"}));
assert.commandWorked(coll.insert({_id: 2, str: "bar"}));
@@ -974,10 +919,9 @@ assert.eq(1, planStage.nWouldDelete);
// findAndModify should return correct results when no collation specified and collection has a
// default collation.
-coll = testDb.collation_findmodify4;
coll.drop();
assert.commandWorked(
- testDb.createCollection(coll.getName(), {collation: {locale: "en_US", strength: 2}}));
+ db.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}}}));
@@ -998,10 +942,9 @@ 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 = testDb.collation_findmodify5;
coll.drop();
assert.commandWorked(
- testDb.createCollection(coll.getName(), {collation: {locale: "en_US", strength: 2}}));
+ db.createCollection(coll.getName(), {collation: {locale: "en_US", strength: 2}}));
assert.commandWorked(coll.insert({_id: 1, str: "foo"}));
assert.eq(null,
coll.findAndModify(
@@ -1014,7 +957,6 @@ assert.eq(null,
//
// mapReduce should return correct results when collation specified and no indexes exist.
-coll = testDb.collation_mapreduce1;
coll.drop();
assert.commandWorked(coll.insert({_id: 1, str: "foo"}));
assert.commandWorked(coll.insert({_id: 2, str: "bar"}));
@@ -1031,10 +973,9 @@ assert.eq(mapReduceOut.results.length, 1);
// mapReduce should return correct results when no collation specified and collection has a
// default collation.
-coll = testDb.collation_mapreduce2;
coll.drop();
assert.commandWorked(
- testDb.createCollection(coll.getName(), {collation: {locale: "en_US", strength: 2}}));
+ db.createCollection(coll.getName(), {collation: {locale: "en_US", strength: 2}}));
assert.commandWorked(coll.insert({_id: 1, str: "foo"}));
var mapReduceOut = coll.mapReduce(
function() {
@@ -1049,10 +990,9 @@ assert.eq(mapReduceOut.results.length, 1);
// mapReduce should return correct results when "simple" collation specified and collection has
// a default collation.
-coll = testDb.collation_mapreduce3;
coll.drop();
assert.commandWorked(
- testDb.createCollection(coll.getName(), {collation: {locale: "en_US", strength: 2}}));
+ db.createCollection(coll.getName(), {collation: {locale: "en_US", strength: 2}}));
assert.commandWorked(coll.insert({_id: 1, str: "foo"}));
var mapReduceOut = coll.mapReduce(
function() {
@@ -1070,12 +1010,10 @@ assert.eq(mapReduceOut.results.length, 0);
//
// Remove should succeed when collation specified and collection does not exist.
-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 = testDb.collation_remove2;
coll.drop();
assert.commandWorked(coll.insert({_id: 1, str: "foo"}));
assert.commandWorked(coll.insert({_id: 2, str: "foo"}));
@@ -1084,7 +1022,6 @@ assert.commandWorked(writeRes);
assert.eq(1, writeRes.nRemoved);
// Explain of remove should return correct results when collation specified.
-coll = testDb.collation_remove3;
coll.drop();
assert.commandWorked(coll.insert({_id: 1, str: "foo"}));
assert.commandWorked(coll.insert({_id: 2, str: "foo"}));
@@ -1097,10 +1034,9 @@ assert.eq(1, planStage.nWouldDelete);
// Remove should return correct results when no collation specified and collection has a default
// collation.
-coll = testDb.collation_remove4;
coll.drop();
assert.commandWorked(
- testDb.createCollection(coll.getName(), {collation: {locale: "en_US", strength: 2}}));
+ db.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);
@@ -1108,10 +1044,9 @@ assert.eq(1, writeRes.nRemoved);
// Remove with idhack should return correct results when no collation specified and collection
// has a default collation.
-coll = testDb.collation_remove5;
coll.drop();
assert.commandWorked(
- testDb.createCollection(coll.getName(), {collation: {locale: "en_US", strength: 2}}));
+ db.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);
@@ -1127,9 +1062,8 @@ assert.eq(1, writeRes.nRemoved);
if (!isClustered) {
// Remove on _id should use idhack stage when query inherits collection default collation.
- coll = testDb.collation_remove6;
coll.drop();
- assert.commandWorked(testDb.createCollection(coll.getName(), {collation: {locale: "en_US"}}));
+ assert.commandWorked(db.createCollection(coll.getName(), {collation: {locale: "en_US"}}));
explainRes = coll.explain("executionStats").remove({_id: "foo"});
assert.commandWorked(explainRes);
planStage = getPlanStage(explainRes.executionStats.executionStages, "IDHACK");
@@ -1138,10 +1072,9 @@ if (!isClustered) {
// Remove should return correct results when "simple" collation specified and collection has
// a default collation.
-coll = testDb.collation_remove7;
coll.drop();
assert.commandWorked(
- testDb.createCollection(coll.getName(), {collation: {locale: "en_US", strength: 2}}));
+ db.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);
@@ -1149,10 +1082,9 @@ assert.eq(0, writeRes.nRemoved);
// Remove on _id should return correct results when "simple" collation specified and
// collection has a default collation.
-coll = testDb.collation_remove8;
coll.drop();
assert.commandWorked(
- testDb.createCollection(coll.getName(), {collation: {locale: "en_US", strength: 2}}));
+ db.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);
@@ -1161,9 +1093,8 @@ assert.eq(0, writeRes.nRemoved);
if (!isClustered) {
// Remove on _id should use idhack stage when explicit query collation matches collection
// default.
- coll = testDb.collation_remove9;
coll.drop();
- assert.commandWorked(testDb.createCollection(coll.getName(), {collation: {locale: "en_US"}}));
+ assert.commandWorked(db.createCollection(coll.getName(), {collation: {locale: "en_US"}}));
explainRes =
coll.explain("executionStats").remove({_id: "foo"}, {collation: {locale: "en_US"}});
assert.commandWorked(explainRes);
@@ -1172,9 +1103,8 @@ if (!isClustered) {
// Remove on _id should not use idhack stage when query collation does not match collection
// default.
- coll = testDb.collation_remove10;
coll.drop();
- assert.commandWorked(testDb.createCollection(coll.getName(), {collation: {locale: "en_US"}}));
+ assert.commandWorked(db.createCollection(coll.getName(), {collation: {locale: "en_US"}}));
explainRes =
coll.explain("executionStats").remove({_id: "foo"}, {collation: {locale: "fr_CA"}});
assert.commandWorked(explainRes);
@@ -1187,13 +1117,11 @@ if (!isClustered) {
//
// Update should succeed when collation specified and collection does not exist.
-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 = testDb.collation_update2;
coll.drop();
assert.commandWorked(coll.insert({_id: 1, str: "foo"}));
assert.commandWorked(coll.insert({_id: 2, str: "foo"}));
@@ -1202,7 +1130,6 @@ writeRes = coll.update(
assert.eq(2, writeRes.nModified);
// Explain of update should return correct results when collation specified.
-coll = testDb.collation_update3;
coll.drop();
assert.commandWorked(coll.insert({_id: 1, str: "foo"}));
assert.commandWorked(coll.insert({_id: 2, str: "foo"}));
@@ -1217,10 +1144,9 @@ assert.eq(2, planStage.nWouldModify);
// Update should return correct results when no collation specified and collection has a default
// collation.
-coll = testDb.collation_update4;
coll.drop();
assert.commandWorked(
- testDb.createCollection(coll.getName(), {collation: {locale: "en_US", strength: 2}}));
+ db.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);
@@ -1228,10 +1154,9 @@ assert.eq(1, writeRes.nMatched);
// Update with idhack should return correct results when no collation specified and collection
// has a default collation.
-coll = testDb.collation_update5;
coll.drop();
assert.commandWorked(
- testDb.createCollection(coll.getName(), {collation: {locale: "en_US", strength: 2}}));
+ db.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);
@@ -1239,9 +1164,8 @@ assert.eq(1, writeRes.nMatched);
if (!isClustered) {
// Update on _id should use idhack stage when query inherits collection default collation.
- coll = testDb.collation_update6;
coll.drop();
- assert.commandWorked(testDb.createCollection(coll.getName(), {collation: {locale: "en_US"}}));
+ assert.commandWorked(db.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");
@@ -1250,10 +1174,9 @@ if (!isClustered) {
// Update should return correct results when "simple" collation specified and collection has
// a default collation.
-coll = testDb.collation_update7;
coll.drop();
assert.commandWorked(
- testDb.createCollection(coll.getName(), {collation: {locale: "en_US", strength: 2}}));
+ db.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);
@@ -1261,10 +1184,9 @@ assert.eq(0, writeRes.nModified);
// Update on _id should return correct results when "simple" collation specified and
// collection has a default collation.
-coll = testDb.collation_update8;
coll.drop();
assert.commandWorked(
- testDb.createCollection(coll.getName(), {collation: {locale: "en_US", strength: 2}}));
+ db.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);
@@ -1273,9 +1195,8 @@ assert.eq(0, writeRes.nModified);
if (!isClustered) {
// Update on _id should use idhack stage when explicitly given query collation matches
// collection default.
- coll = testDb.collation_update9;
coll.drop();
- assert.commandWorked(testDb.createCollection(coll.getName(), {collation: {locale: "en_US"}}));
+ assert.commandWorked(db.createCollection(coll.getName(), {collation: {locale: "en_US"}}));
explainRes = coll.explain("executionStats").update({_id: "foo"}, {$set: {other: 99}}, {
collation: {locale: "en_US"}
});
@@ -1285,9 +1206,8 @@ if (!isClustered) {
// Update on _id should not use idhack stage when query collation does not match collection
// default.
- coll = testDb.collation_update10;
coll.drop();
- assert.commandWorked(testDb.createCollection(coll.getName(), {collation: {locale: "en_US"}}));
+ assert.commandWorked(db.createCollection(coll.getName(), {collation: {locale: "en_US"}}));
explainRes = coll.explain("executionStats").update({_id: "foo"}, {$set: {other: 99}}, {
collation: {locale: "fr_CA"}
});
@@ -1301,9 +1221,8 @@ if (!isClustered) {
//
// $geoNear should fail when collation is specified but the collection does not exist.
-coll = testDb.collation_geonear1;
coll.drop();
-assert.commandFailedWithCode(testDb.runCommand({
+assert.commandFailedWithCode(db.runCommand({
aggregate: coll.getName(),
cursor: {},
pipeline: [{
@@ -1317,10 +1236,9 @@ assert.commandFailedWithCode(testDb.runCommand({
ErrorCodes.NamespaceNotFound);
// $geoNear rejects the now-deprecated "collation" option.
-coll = testDb.collation_geonear2;
coll.drop();
assert.commandWorked(coll.insert({geo: {type: "Point", coordinates: [0, 0]}, str: "abc"}));
-assert.commandFailedWithCode(testDb.runCommand({
+assert.commandFailedWithCode(db.runCommand({
aggregate: coll.getName(),
cursor: {},
pipeline: [{
@@ -1373,20 +1291,18 @@ 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 = testDb.collation_geonear3;
coll.drop();
assert.commandWorked(
- testDb.createCollection(coll.getName(), {collation: {locale: "en_US", strength: 2}}));
+ db.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 = testDb.collation_geonear4;
coll.drop();
assert.commandWorked(
- testDb.createCollection(coll.getName(), {collation: {locale: "en_US", strength: 2}}));
+ db.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());
@@ -1397,7 +1313,6 @@ 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 = testDb.collation_nearsphere1;
coll.drop();
assert.eq(
0,
@@ -1407,7 +1322,6 @@ assert.eq(
// Find with $nearSphere should return correct results when collation specified and string
// predicate not indexed.
-coll = testDb.collation_nearsphere2;
coll.drop();
assert.commandWorked(coll.insert({geo: {type: "Point", coordinates: [0, 0]}, str: "abc"}));
assert.commandWorked(coll.createIndex({geo: "2dsphere"}));
@@ -1472,7 +1386,6 @@ assert.eq(
var bulk;
// update().
-coll = testDb.collation_bulkupdate;
coll.drop();
assert.commandWorked(coll.insert({_id: 1, str: "foo"}));
assert.commandWorked(coll.insert({_id: 2, str: "foo"}));
@@ -1483,7 +1396,6 @@ assert.commandWorked(writeRes);
assert.eq(2, writeRes.nModified);
// updateOne().
-coll = testDb.collation_bulkupdateone;
coll.drop();
assert.commandWorked(coll.insert({_id: 1, str: "foo"}));
assert.commandWorked(coll.insert({_id: 2, str: "foo"}));
@@ -1494,7 +1406,6 @@ assert.commandWorked(writeRes);
assert.eq(1, writeRes.nModified);
// replaceOne().
-coll = testDb.collation_bulkreplaceone1;
coll.drop();
assert.commandWorked(coll.insert({_id: 1, str: "foo"}));
assert.commandWorked(coll.insert({_id: 2, str: "foo"}));
@@ -1505,7 +1416,6 @@ assert.commandWorked(writeRes);
assert.eq(1, writeRes.nModified);
// replaceOne() with upsert().
-coll = testDb.collation_bulkreplaceone2;
coll.drop();
assert.commandWorked(coll.insert({_id: 1, str: "foo"}));
assert.commandWorked(coll.insert({_id: 2, str: "foo"}));
@@ -1524,7 +1434,6 @@ assert.eq(0, writeRes.nUpserted);
assert.eq(1, writeRes.nModified);
// removeOne().
-coll = testDb.collation_bulkremoveone;
coll.drop();
assert.commandWorked(coll.insert({_id: 1, str: "foo"}));
assert.commandWorked(coll.insert({_id: 2, str: "foo"}));
@@ -1535,7 +1444,6 @@ assert.commandWorked(writeRes);
assert.eq(1, writeRes.nRemoved);
// remove().
-coll = testDb.collation_bulkremove;
coll.drop();
assert.commandWorked(coll.insert({_id: 1, str: "foo"}));
assert.commandWorked(coll.insert({_id: 2, str: "foo"}));
@@ -1550,7 +1458,6 @@ assert.eq(2, writeRes.nRemoved);
//
// deleteOne().
-coll = testDb.collation_deleteone;
coll.drop();
assert.commandWorked(coll.insert({_id: 1, str: "foo"}));
assert.commandWorked(coll.insert({_id: 2, str: "foo"}));
@@ -1558,7 +1465,6 @@ res = coll.deleteOne({str: "FOO"}, {collation: {locale: "en_US", strength: 2}});
assert.eq(1, res.deletedCount);
// deleteMany().
-coll = testDb.collation_deletemany;
coll.drop();
assert.commandWorked(coll.insert({_id: 1, str: "foo"}));
assert.commandWorked(coll.insert({_id: 2, str: "foo"}));
@@ -1566,7 +1472,6 @@ res = coll.deleteMany({str: "FOO"}, {collation: {locale: "en_US", strength: 2}})
assert.eq(2, res.deletedCount);
// findOneAndDelete().
-coll = testDb.collation_findonedelete;
coll.drop();
assert.commandWorked(coll.insert({_id: 1, str: "foo"}));
assert.eq({_id: 1, str: "foo"},
@@ -1574,7 +1479,6 @@ assert.eq({_id: 1, str: "foo"},
assert.eq(null, coll.findOne({_id: 1}));
// findOneAndReplace().
-coll = testDb.collation_findonereplace;
coll.drop();
assert.commandWorked(coll.insert({_id: 1, str: "foo"}));
assert.eq({_id: 1, str: "foo"},
@@ -1583,7 +1487,6 @@ assert.eq({_id: 1, str: "foo"},
assert.neq(null, coll.findOne({str: "bar"}));
// findOneAndUpdate().
-coll = testDb.collation_findoneupdate;
coll.drop();
assert.commandWorked(coll.insert({_id: 1, str: "foo"}));
assert.eq({_id: 1, str: "foo"},
@@ -1592,7 +1495,6 @@ assert.eq({_id: 1, str: "foo"},
assert.neq(null, coll.findOne({other: 99}));
// replaceOne().
-coll = testDb.collation_replaceone;
coll.drop();
assert.commandWorked(coll.insert({_id: 1, str: "foo"}));
assert.commandWorked(coll.insert({_id: 2, str: "foo"}));
@@ -1600,7 +1502,6 @@ res = coll.replaceOne({str: "FOO"}, {str: "bar"}, {collation: {locale: "en_US",
assert.eq(1, res.modifiedCount);
// updateOne().
-coll = testDb.collation_updateone;
coll.drop();
assert.commandWorked(coll.insert({_id: 1, str: "foo"}));
assert.commandWorked(coll.insert({_id: 2, str: "foo"}));
@@ -1609,7 +1510,6 @@ res =
assert.eq(1, res.modifiedCount);
// updateMany().
-coll = testDb.collation_updatemany;
coll.drop();
assert.commandWorked(coll.insert({_id: 1, str: "foo"}));
assert.commandWorked(coll.insert({_id: 2, str: "foo"}));
@@ -1618,7 +1518,6 @@ res =
assert.eq(2, res.modifiedCount);
// updateOne with bulkWrite().
-coll = testDb.collation_updateonebulkwrite;
coll.drop();
assert.commandWorked(coll.insert({_id: 1, str: "foo"}));
assert.commandWorked(coll.insert({_id: 2, str: "foo"}));
@@ -1645,7 +1544,6 @@ for (let backwards of [undefined, null]) {
}
// updateMany with bulkWrite().
-coll = testDb.collation_updatemanybulkwrite;
coll.drop();
assert.commandWorked(coll.insert({_id: 1, str: "foo"}));
assert.commandWorked(coll.insert({_id: 2, str: "foo"}));
@@ -1659,7 +1557,6 @@ res = coll.bulkWrite([{
assert.eq(2, res.matchedCount);
// replaceOne with bulkWrite().
-coll = testDb.collation_replaceonebulkwrite;
coll.drop();
assert.commandWorked(coll.insert({_id: 1, str: "foo"}));
assert.commandWorked(coll.insert({_id: 2, str: "foo"}));
@@ -1670,7 +1567,6 @@ res = coll.bulkWrite([{
assert.eq(1, res.matchedCount);
// deleteOne with bulkWrite().
-coll = testDb.collation_deleteonebulkwrite;
coll.drop();
assert.commandWorked(coll.insert({_id: 1, str: "foo"}));
assert.commandWorked(coll.insert({_id: 2, str: "foo"}));
@@ -1679,7 +1575,6 @@ res = coll.bulkWrite(
assert.eq(1, res.deletedCount);
// deleteMany with bulkWrite().
-coll = testDb.collation_deletemanybulkwrite;
coll.drop();
assert.commandWorked(coll.insert({_id: 1, str: "foo"}));
assert.commandWorked(coll.insert({_id: 2, str: "foo"}));
@@ -1688,7 +1583,6 @@ res = coll.bulkWrite(
assert.eq(2, res.deletedCount);
// Two deleteOne ops with bulkWrite using different collations.
-coll = testDb.collation_deleteone2collation;
coll.drop();
assert.commandWorked(coll.insert({_id: 1, str: "foo"}));
assert.commandWorked(coll.insert({_id: 2, str: "bar"}));
@@ -1700,19 +1594,18 @@ assert.eq(2, res.deletedCount);
// applyOps.
if (!isMongos) {
- coll = testDb.collation_applyops;
coll.drop();
assert.commandWorked(
- testDb.createCollection(coll.getName(), {collation: {locale: "en_US", strength: 2}}));
+ db.createCollection("collation", {collation: {locale: "en_US", strength: 2}}));
assert.commandWorked(coll.insert({_id: "foo", x: 5, str: "bar"}));
// preCondition.q respects collection default collation.
- assert.commandFailed(testDb.runCommand({
+ assert.commandFailed(db.runCommand({
applyOps: [{op: "u", ns: coll.getFullName(), o2: {_id: "foo"}, o: {$set: {x: 6}}}],
preCondition: [{ns: coll.getFullName(), q: {_id: "not foo"}, res: {str: "bar"}}]
}));
assert.eq(5, coll.findOne({_id: "foo"}).x);
- assert.commandWorked(testDb.runCommand({
+ assert.commandWorked(db.runCommand({
applyOps: [{op: "u", ns: coll.getFullName(), o2: {_id: "foo"}, o: {$set: {x: 6}}}],
preCondition: [{ns: coll.getFullName(), q: {_id: "FOO"}, res: {str: "bar"}}]
}));
@@ -1740,16 +1633,15 @@ 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 = testDb.collation_cloned;
+ const clonedColl = db.collation_cloned;
- coll = testDb.collation_orig;
coll.drop();
clonedColl.drop();
// Create a collection with a non-simple default collation.
assert.commandWorked(
- testDb.runCommand({create: coll.getName(), collation: {locale: "en", strength: 2}}));
- const originalCollectionInfos = testDb.getCollectionInfos({name: coll.getName()});
+ db.runCommand({create: coll.getName(), collation: {locale: "en", strength: 2}}));
+ const originalCollectionInfos = db.getCollectionInfos({name: coll.getName()});
assert.eq(originalCollectionInfos.length, 1, tojson(originalCollectionInfos));
assert.commandWorked(coll.insert({_id: "FOO"}));
@@ -1758,10 +1650,10 @@ if (!isMongos) {
coll.find({_id: "foo"}).toArray(),
"query should have performed a case-insensitive match");
- var cloneCollOutput = testDb.runCommand(
+ var cloneCollOutput = db.runCommand(
{cloneCollectionAsCapped: coll.getName(), toCollection: clonedColl.getName(), size: 4096});
assert.commandWorked(cloneCollOutput);
- const clonedCollectionInfos = testDb.getCollectionInfos({name: clonedColl.getName()});
+ const clonedCollectionInfos = db.getCollectionInfos({name: clonedColl.getName()});
assert.eq(clonedCollectionInfos.length, 1, tojson(clonedCollectionInfos));
assert.eq(originalCollectionInfos[0].options.collation,
clonedCollectionInfos[0].options.collation);
@@ -1769,7 +1661,6 @@ if (!isMongos) {
}
// Test that the find command's min/max options respect the collation.
-coll = testDb.collation_minmax1;
coll.drop();
assert.commandWorked(coll.insert({str: "a"}));
assert.commandWorked(coll.insert({str: "A"}));
@@ -1830,7 +1721,6 @@ assert.eq(4,
.itcount());
// Ensure results from index with min/max query are sorted to match requested collation.
-coll = testDb.collation_minmax2;
coll.drop();
assert.commandWorked(coll.createIndex({a: 1, b: 1}));
assert.commandWorked(
@@ -1865,7 +1755,7 @@ explainRes = coll.find({}, {_id: 0})
.sort({a: 1, b: 1})
.explain();
assert.commandWorked(explainRes);
-assert(planHasStage(testDb, getWinningPlan(explainRes.queryPlanner), "SORT"));
+assert(planHasStage(db, 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.