summaryrefslogtreecommitdiff
path: root/jstests/aggregation/sources/redact/collation_redact.js
diff options
context:
space:
mode:
Diffstat (limited to 'jstests/aggregation/sources/redact/collation_redact.js')
-rw-r--r--jstests/aggregation/sources/redact/collation_redact.js67
1 files changed, 33 insertions, 34 deletions
diff --git a/jstests/aggregation/sources/redact/collation_redact.js b/jstests/aggregation/sources/redact/collation_redact.js
index 36304e9a7f2..7ff1e1ad4f1 100644
--- a/jstests/aggregation/sources/redact/collation_redact.js
+++ b/jstests/aggregation/sources/redact/collation_redact.js
@@ -3,38 +3,37 @@
// Test that the $redact stage respects the collation.
(function() {
- "use strict";
-
- var caseInsensitive = {collation: {locale: "en_US", strength: 2}};
-
- var coll = db.collation_redact;
- coll.drop();
- assert.writeOK(coll.insert({a: "a"}));
-
- // Test that $redact respects an explicit collation. Since the top-level of the document gets
- // pruned, we end up redacting the entire document and returning no results.
- assert.eq(0,
- coll.aggregate([{$redact: {$cond: [{$eq: ["A", "a"]}, "$$PRUNE", "$$KEEP"]}}],
- caseInsensitive)
- .itcount());
-
- coll.drop();
- assert.commandWorked(db.createCollection(coll.getName(), caseInsensitive));
- assert.writeOK(coll.insert({a: "a"}));
-
- // Test that $redact respects the inherited collation. Since the top-level of the document gets
- // pruned, we end up redacting the entire document and returning no results.
- assert.eq(
- 0,
- coll.aggregate([{$redact: {$cond: [{$eq: ["A", "a"]}, "$$PRUNE", "$$KEEP"]}}]).itcount());
-
- // Test that a $match which can be optimized to be pushed before the $redact respects the
- // collation.
- assert.eq(1, coll.aggregate([{$redact: "$$KEEP"}, {$match: {a: "A"}}]).itcount());
-
- // Comparison to the internal constants bound to the $$KEEP, $$PRUNE, and $$DESCEND variable
- // should not respect the collation.
- assert.throws(() => coll.aggregate([{$redact: "KEEP"}], caseInsensitive));
- assert.throws(() => coll.aggregate([{$redact: "PRUNE"}], caseInsensitive));
- assert.throws(() => coll.aggregate([{$redact: "REDACT"}], caseInsensitive));
+"use strict";
+
+var caseInsensitive = {collation: {locale: "en_US", strength: 2}};
+
+var coll = db.collation_redact;
+coll.drop();
+assert.writeOK(coll.insert({a: "a"}));
+
+// Test that $redact respects an explicit collation. Since the top-level of the document gets
+// pruned, we end up redacting the entire document and returning no results.
+assert.eq(
+ 0,
+ coll.aggregate([{$redact: {$cond: [{$eq: ["A", "a"]}, "$$PRUNE", "$$KEEP"]}}], caseInsensitive)
+ .itcount());
+
+coll.drop();
+assert.commandWorked(db.createCollection(coll.getName(), caseInsensitive));
+assert.writeOK(coll.insert({a: "a"}));
+
+// Test that $redact respects the inherited collation. Since the top-level of the document gets
+// pruned, we end up redacting the entire document and returning no results.
+assert.eq(0,
+ coll.aggregate([{$redact: {$cond: [{$eq: ["A", "a"]}, "$$PRUNE", "$$KEEP"]}}]).itcount());
+
+// Test that a $match which can be optimized to be pushed before the $redact respects the
+// collation.
+assert.eq(1, coll.aggregate([{$redact: "$$KEEP"}, {$match: {a: "A"}}]).itcount());
+
+// Comparison to the internal constants bound to the $$KEEP, $$PRUNE, and $$DESCEND variable
+// should not respect the collation.
+assert.throws(() => coll.aggregate([{$redact: "KEEP"}], caseInsensitive));
+assert.throws(() => coll.aggregate([{$redact: "PRUNE"}], caseInsensitive));
+assert.throws(() => coll.aggregate([{$redact: "REDACT"}], caseInsensitive));
})();