summaryrefslogtreecommitdiff
path: root/jstests/noPassthroughWithMongod
diff options
context:
space:
mode:
authorLouis Williams <louis.williams@mongodb.com>2018-02-06 10:59:17 -0500
committerLouis Williams <louis.williams@mongodb.com>2018-02-12 10:42:54 -0500
commit74e24d88efe4a08a8d1e4c71229afb62b503bf73 (patch)
treef1b9bbf86c2c6ea52144853876eddd0901da345b /jstests/noPassthroughWithMongod
parent4b2f7438ec3494cdf5f4f996bc1ac955a0698f40 (diff)
downloadmongo-74e24d88efe4a08a8d1e4c71229afb62b503bf73.tar.gz
SERVER-31161 Index created through applyOps command should not inherit collection default collation
(cherry picked from commit 49dfa0c0e938c265f987b585f3d41ae12a64f65a)
Diffstat (limited to 'jstests/noPassthroughWithMongod')
-rw-r--r--jstests/noPassthroughWithMongod/apply_ops_index_collation.js80
1 files changed, 80 insertions, 0 deletions
diff --git a/jstests/noPassthroughWithMongod/apply_ops_index_collation.js b/jstests/noPassthroughWithMongod/apply_ops_index_collation.js
new file mode 100644
index 00000000000..6248bc63b0f
--- /dev/null
+++ b/jstests/noPassthroughWithMongod/apply_ops_index_collation.js
@@ -0,0 +1,80 @@
+// Cannot implicitly shard accessed collections because of collection existing when none
+// expected.
+// @tags: [assumes_no_implicit_collection_creation_after_drop]
+
+// Tests creation of indexes using applyOps for collections with a non-simple default collation.
+// Indexes created through applyOps should be built exactly according to their index spec, without
+// inheriting the collection default collation, since this is how the oplog entries are replicated.
+// TODO SERVER-31435: Move this test into core once applyOps with createIndexes replicates
+// correctly.
+(function() {
+ "use strict";
+
+ load("jstests/libs/get_index_helpers.js");
+
+ const coll = db.apply_ops_index_collation;
+ coll.drop();
+ assert.commandWorked(db.createCollection(coll.getName(), {collation: {locale: "fr_CA"}}));
+
+ // An index created using an insert-style oplog entry with a non-simple collation does not
+ // inherit the collection default collation.
+ let res = assert.commandWorked(db.adminCommand({
+ applyOps: [{
+ op: "i",
+ ns: db.system.indexes.getFullName(),
+ o: {
+ v: 2,
+ key: {c: 1},
+ name: "c_1_en",
+ ns: coll.getFullName(),
+ collation: {
+ locale: "en_US",
+ caseLevel: false,
+ caseFirst: "off",
+ strength: 3,
+ numericOrdering: false,
+ alternate: "non-ignorable",
+ maxVariable: "punct",
+ normalization: false,
+ backwards: false,
+ version: "57.1"
+ }
+ }
+ }]
+ }));
+ let allIndexes = coll.getIndexes();
+ let spec = GetIndexHelpers.findByName(allIndexes, "c_1_en");
+ assert.neq(null, spec, "Index 'c_1_en' not found: " + tojson(allIndexes));
+ assert.eq(2, spec.v, tojson(spec));
+ assert.eq("en_US", spec.collation.locale, tojson(spec));
+
+ // An index created using an insert-style oplog entry with a simple collation does not inherit
+ // the collection default collation.
+ res = assert.commandWorked(db.adminCommand({
+ applyOps: [{
+ op: "i",
+ ns: db.system.indexes.getFullName(),
+ o: {v: 2, key: {c: 1}, name: "c_1", ns: coll.getFullName()}
+ }]
+ }));
+ allIndexes = coll.getIndexes();
+ spec = GetIndexHelpers.findByName(allIndexes, "c_1");
+ assert.neq(null, spec, "Index 'c_1' not found: " + tojson(allIndexes));
+ assert.eq(2, spec.v, tojson(spec));
+ assert(!spec.hasOwnProperty("collation"), tojson(spec));
+
+ // A v=1 index created using an insert-style oplog entry does not inherit the collection default
+ // collation.
+ res = assert.commandWorked(db.adminCommand({
+ applyOps: [{
+ op: "i",
+ ns: db.system.indexes.getFullName(),
+ o: {v: 1, key: {d: 1}, name: "d_1", ns: coll.getFullName()}
+ }]
+ }));
+ allIndexes = coll.getIndexes();
+ spec = GetIndexHelpers.findByName(allIndexes, "d_1");
+ assert.neq(null, spec, "Index 'd_1' not found: " + tojson(allIndexes));
+ assert.eq(1, spec.v, tojson(spec));
+ assert(!spec.hasOwnProperty("collation"), tojson(spec));
+})();