summaryrefslogtreecommitdiff
path: root/jstests/noPassthroughWithMongod
diff options
context:
space:
mode:
authoryarai <yuta.arai@10gen.com>2018-09-24 17:31:19 -0400
committeryarai <yuta.arai@10gen.com>2018-09-26 12:57:43 -0400
commit54d601d3fd7297f71380178ee34029479edea944 (patch)
treed99e1482e1483237e5943c18687d6e97d8ddab97 /jstests/noPassthroughWithMongod
parent82aa5b5c45919d89ce791bca3e11cc82c3b91311 (diff)
downloadmongo-54d601d3fd7297f71380178ee34029479edea944.tar.gz
SERVER-36609 Modify allPaths indexes to support equality to empty array
Diffstat (limited to 'jstests/noPassthroughWithMongod')
-rw-r--r--jstests/noPassthroughWithMongod/all_paths_basic_index_bounds.js1
-rw-r--r--jstests/noPassthroughWithMongod/wildcard_index_empty_arrays.js50
2 files changed, 51 insertions, 0 deletions
diff --git a/jstests/noPassthroughWithMongod/all_paths_basic_index_bounds.js b/jstests/noPassthroughWithMongod/all_paths_basic_index_bounds.js
index 2c0463130b4..9eef97a7da4 100644
--- a/jstests/noPassthroughWithMongod/all_paths_basic_index_bounds.js
+++ b/jstests/noPassthroughWithMongod/all_paths_basic_index_bounds.js
@@ -73,6 +73,7 @@
{expression: {$ne: null, $exists: true}, bounds: ['[MinKey, MaxKey]'], subpathBounds: true},
// In principle we could have tighter bounds for this. See SERVER-36765.
{expression: {$eq: null, $exists: true}, bounds: ['[MinKey, MaxKey]'], subpathBounds: true},
+ {expression: {$eq: []}, bounds: ['[undefined, undefined]', '[[], []]']}
];
// Given a keyPattern and (optional) pathProjection, this function builds a $** index on the
diff --git a/jstests/noPassthroughWithMongod/wildcard_index_empty_arrays.js b/jstests/noPassthroughWithMongod/wildcard_index_empty_arrays.js
new file mode 100644
index 00000000000..77b20b5ba8e
--- /dev/null
+++ b/jstests/noPassthroughWithMongod/wildcard_index_empty_arrays.js
@@ -0,0 +1,50 @@
+/**
+ * Tests that wildcard indexes will correctly match for empty arrays.
+ */
+(function() {
+ "use strict";
+
+ load("jstests/aggregation/extras/utils.js"); // For arrayEq.
+
+ const coll = db.wildcard_empty_arrays;
+ coll.drop();
+
+ const assertArrayEq = (l, r) => assert(arrayEq(l, r), tojson(l) + " != " + tojson(r));
+
+ // Required in order to build $** indexes.
+ assert.commandWorked(
+ db.adminCommand({setParameter: 1, internalQueryAllowAllPathsIndexes: true}));
+
+ try {
+ const indexWildcard = {"$**": 1};
+ assert.commandWorked(coll.createIndex(indexWildcard));
+
+ assert.commandWorked(coll.insert({a: 1, b: 1, c: [], d: {e: [5, 6]}}));
+ assert.commandWorked(coll.insert({a: 2, b: 2, c: [1, 2], d: {e: []}}));
+ assert.commandWorked(coll.insert({a: 1, b: 2, c: [3, 4], d: {e: [7, 8]}, f: [{g: []}]}));
+ assert.commandWorked(coll.insert({a: 2, b: [[]], c: 1, d: 4}));
+
+ // $** index matches empty array.
+ assertArrayEq(coll.find({c: []}, {_id: 0}).hint(indexWildcard).toArray(),
+ [{a: 1, b: 1, c: [], d: {e: [5, 6]}}]);
+
+ // $** index supports equality to array offset.
+ assertArrayEq(coll.find({"c.0": 1}, {_id: 0}).hint(indexWildcard).toArray(),
+ [{a: 2, b: 2, c: [1, 2], d: {e: []}}]);
+
+ // $** index matches empty array nested in object.
+ assertArrayEq(coll.find({"d.e": []}, {_id: 0}).hint(indexWildcard).toArray(),
+ [{a: 2, b: 2, c: [1, 2], d: {e: []}}]);
+
+ // $** index matches empty array nested within an array of objects.
+ assertArrayEq(coll.find({"f.0.g": []}, {_id: 0}).hint(indexWildcard).toArray(),
+ [{a: 1, b: 2, c: [3, 4], d: {e: [7, 8]}, f: [{g: []}]}]);
+
+ // $** index matches empty array nested within an array.
+ assertArrayEq(coll.find({"b": []}, {_id: 0}).hint(indexWildcard).toArray(),
+ [{a: 2, b: [[]], c: 1, d: 4}]);
+ } finally {
+ // Disable $** indexes once the tests have either completed or failed.
+ db.adminCommand({setParameter: 1, internalQueryAllowAllPathsIndexes: false});
+ }
+})(); \ No newline at end of file