diff options
author | Benety Goh <benety@mongodb.com> | 2021-08-16 11:26:47 -0400 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2021-08-16 16:11:02 +0000 |
commit | c1e688cf7ad41a0d49d5b64f8abd88d7b9435f9b (patch) | |
tree | 5d9f4362a8473acd7e91ecfe17e043359413a6a6 /jstests/core/fts_index3.js | |
parent | e030e652c5464d9ac4071c5ddf9e8938c23d9549 (diff) | |
download | mongo-c1e688cf7ad41a0d49d5b64f8abd88d7b9435f9b.tar.gz |
SERVER-59239 clean up fts_index3.js
Diffstat (limited to 'jstests/core/fts_index3.js')
-rw-r--r-- | jstests/core/fts_index3.js | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/jstests/core/fts_index3.js b/jstests/core/fts_index3.js index c255b645d90..ac4730d0bd0 100644 --- a/jstests/core/fts_index3.js +++ b/jstests/core/fts_index3.js @@ -6,10 +6,14 @@ // ] // Test that updates to fields in a text-indexed document are correctly reflected in the text index. -var coll = db.fts_index3; +(function() { +'use strict'; +const collNamePrefix = 'fts_index3_'; +let collCount = 0; // 1) Create a text index on a single field, insert a document, update the value of the field, and // verify that $text with the new value returns the document. +let coll = db.getCollection(collNamePrefix + collCount++); coll.drop(); assert.commandWorked(coll.createIndex({a: "text"})); assert.commandWorked(coll.insert({a: "hello"})); @@ -19,6 +23,7 @@ assert.eq(0, coll.find({$text: {$search: "hello"}}).itcount()); assert.eq(1, coll.find({$text: {$search: "world"}}).itcount()); // 2) Same as #1, but with a wildcard text index. +coll = db.getCollection(collNamePrefix + collCount++); coll.drop(); assert.commandWorked(coll.createIndex({"$**": "text"})); assert.commandWorked(coll.insert({a: "hello"})); @@ -29,6 +34,7 @@ assert.eq(1, coll.find({$text: {$search: "world"}}).itcount()); // 3) Create a compound text index with an index prefix, insert a document, update the value of the // index prefix field, and verify that $text with the new value returns the document. +coll = db.getCollection(collNamePrefix + collCount++); coll.drop(); assert.commandWorked(coll.createIndex({a: 1, b: "text"})); assert.commandWorked(coll.insert({a: 1, b: "hello"})); @@ -38,6 +44,7 @@ assert.eq(0, coll.find({a: 1, $text: {$search: "hello"}}).itcount()); assert.eq(1, coll.find({a: 2, $text: {$search: "hello"}}).itcount()); // 4) Same as #3, but with a wildcard text index. +coll = db.getCollection(collNamePrefix + collCount++); coll.drop(); assert.commandWorked(coll.createIndex({a: 1, "$**": "text"})); assert.commandWorked(coll.insert({a: 1, b: "hello"})); @@ -48,6 +55,7 @@ assert.eq(1, coll.find({a: 2, $text: {$search: "hello"}}).itcount()); // 5) Create a compound text index with an index suffix, insert a document, update the value of the // index suffix field, and verify that $text with the new value returns the document. +coll = db.getCollection(collNamePrefix + collCount++); coll.drop(); assert.commandWorked(coll.createIndex({a: "text", b: 1})); assert.commandWorked(coll.insert({a: "hello", b: 1})); @@ -57,6 +65,7 @@ assert.eq(0, coll.find({b: 1, $text: {$search: "hello"}}).itcount()); assert.eq(1, coll.find({b: 2, $text: {$search: "hello"}}).itcount()); // 6) Same as #5, but with a wildcard text index. +coll = db.getCollection(collNamePrefix + collCount++); coll.drop(); assert.commandWorked(coll.createIndex({"$**": "text", b: 1})); assert.commandWorked(coll.insert({a: "hello", b: 1})); @@ -67,6 +76,7 @@ assert.eq(1, coll.find({b: 2, $text: {$search: "hello"}}).itcount()); // 7) Create a text index on a single field, insert a document, update the language of the document // (so as to change the stemming), and verify that $text with the new language returns the document. +coll = db.getCollection(collNamePrefix + collCount++); coll.drop(); assert.commandWorked(coll.createIndex({a: "text"})); assert.commandWorked(coll.insert({a: "testing", language: "es"})); @@ -77,6 +87,7 @@ assert.eq(0, coll.find({$text: {$search: "testing", $language: "es"}}).itcount() assert.eq(1, coll.find({$text: {$search: "testing", $language: "en"}}).itcount()); // 8) Same as #7, but with a wildcard text index. +coll = db.getCollection(collNamePrefix + collCount++); coll.drop(); assert.commandWorked(coll.createIndex({"$**": "text"})); assert.commandWorked(coll.insert({a: "testing", language: "es"})); @@ -89,6 +100,7 @@ assert.eq(1, coll.find({$text: {$search: "testing", $language: "en"}}).itcount() // 9) Create a text index on a single nested field, insert a document, update the language of the // subdocument (so as to change the stemming), and verify that $text with the new language returns // the document. +coll = db.getCollection(collNamePrefix + collCount++); coll.drop(); assert.commandWorked(coll.createIndex({"a.b": "text"})); assert.commandWorked(coll.insert({a: {b: "testing", language: "es"}})); @@ -99,6 +111,7 @@ assert.eq(0, coll.find({$text: {$search: "testing", $language: "es"}}).itcount() assert.eq(1, coll.find({$text: {$search: "testing", $language: "en"}}).itcount()); // 10) Same as #9, but with a wildcard text index. +coll = db.getCollection(collNamePrefix + collCount++); coll.drop(); assert.commandWorked(coll.createIndex({"$**": "text"})); assert.commandWorked(coll.insert({a: {b: "testing", language: "es"}})); @@ -111,6 +124,7 @@ assert.eq(1, coll.find({$text: {$search: "testing", $language: "en"}}).itcount() // 11) Create a text index on a single field with a custom language override, insert a document, // update the language of the document (so as to change the stemming), and verify that $text with // the new language returns the document. +coll = db.getCollection(collNamePrefix + collCount++); coll.drop(); assert.commandWorked(coll.createIndex({a: "text"}, {language_override: "idioma"})); assert.commandWorked(coll.insert({a: "testing", idioma: "es"})); @@ -121,6 +135,7 @@ assert.eq(0, coll.find({$text: {$search: "testing", $language: "es"}}).itcount() assert.eq(1, coll.find({$text: {$search: "testing", $language: "en"}}).itcount()); // 12) Same as #11, but with a wildcard text index. +coll = db.getCollection(collNamePrefix + collCount++); coll.drop(); assert.commandWorked(coll.createIndex({"$**": "text"}, {language_override: "idioma"})); assert.commandWorked(coll.insert({a: "testing", idioma: "es"})); @@ -129,3 +144,4 @@ assert.eq(0, coll.find({$text: {$search: "testing", $language: "en"}}).itcount() assert.commandWorked(coll.update({}, {$set: {idioma: "en"}})); assert.eq(0, coll.find({$text: {$search: "testing", $language: "es"}}).itcount()); assert.eq(1, coll.find({$text: {$search: "testing", $language: "en"}}).itcount()); +})(); |