summaryrefslogtreecommitdiff
path: root/jstests
diff options
context:
space:
mode:
authoryarai <yuta.arai@10gen.com>2018-09-25 17:27:22 -0400
committeryarai <yuta.arai@10gen.com>2018-09-26 17:21:31 -0400
commit86056fd24d35c81600891f79dd83d633a7493a77 (patch)
treec5a3864846e1b77215d9313aa2300fc65473047a /jstests
parent747a005fb46d3432d576fe56051b0f476e2d2c96 (diff)
downloadmongo-86056fd24d35c81600891f79dd83d633a7493a77.tar.gz
SERVER-35335 Ban the min/max find command options for wildcard indexes
Diffstat (limited to 'jstests')
-rw-r--r--jstests/noPassthroughWithMongod/all_paths_hint.js1
-rw-r--r--jstests/noPassthroughWithMongod/wildcard_index_minmax.js95
2 files changed, 95 insertions, 1 deletions
diff --git a/jstests/noPassthroughWithMongod/all_paths_hint.js b/jstests/noPassthroughWithMongod/all_paths_hint.js
index 369488af54c..052848c636e 100644
--- a/jstests/noPassthroughWithMongod/all_paths_hint.js
+++ b/jstests/noPassthroughWithMongod/all_paths_hint.js
@@ -99,7 +99,6 @@
[{a: 2, b: 2, c: {d: 1, e: 2}}, {a: 1, b: 1, c: {d: 1, e: 1}}]);
// Min/max with $** index hint.
- // TODO SERVER-35335: Confirm expected $** min/max behavior when hint is specified.
assert.commandFailedWithCode(
db.runCommand(
{find: coll.getName(), filter: {"b": 1}, min: {"a": 1}, hint: {"$**": 1}}),
diff --git a/jstests/noPassthroughWithMongod/wildcard_index_minmax.js b/jstests/noPassthroughWithMongod/wildcard_index_minmax.js
new file mode 100644
index 00000000000..006e92069c1
--- /dev/null
+++ b/jstests/noPassthroughWithMongod/wildcard_index_minmax.js
@@ -0,0 +1,95 @@
+/**
+ * Tests that min/max is not supported for wildcard index.
+ */
+(function() {
+ "use strict";
+
+ load("jstests/aggregation/extras/utils.js"); // For arrayEq.
+
+ const coll = db.wildcard_index_minmax;
+ 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 {
+ assert.commandWorked(coll.createIndex({"$**": 1}));
+
+ assert.commandWorked(coll.insert({a: 1, b: 1}));
+ assert.commandWorked(coll.insert({a: 1, b: 2}));
+ assert.commandWorked(coll.insert({a: 2, b: 1}));
+ assert.commandWorked(coll.insert({a: 2, b: 2}));
+
+ // Throws error for $** index min.
+ assert.commandFailedWithCode(
+ db.runCommand({find: coll.getName(), min: {"a": 0.5}, hint: {"$**": 1}}),
+ ErrorCodes.BadValue);
+
+ // Throws error for $** index max.
+ assert.commandFailedWithCode(
+ db.runCommand({find: coll.getName(), max: {"a": 1.5}, hint: {"$**": 1}}),
+ ErrorCodes.BadValue);
+
+ // Throws error for $** index min/max.
+ assert.commandFailedWithCode(
+ db.runCommand(
+ {find: coll.getName(), min: {"a": 0.5}, max: {"a": 1.5}, hint: {"$**": 1}}),
+ ErrorCodes.BadValue);
+
+ // Throws error for $** index min with filter of a different value.
+ assert.commandFailedWithCode(
+ db.runCommand(
+ {find: coll.getName(), filter: {"a": 2}, min: {"a": 1}, hint: {"$**": 1}}),
+ ErrorCodes.BadValue);
+
+ // Throws error for $** index max with filter of a different value.
+ assert.commandFailedWithCode(
+ db.runCommand(
+ {find: coll.getName(), filter: {"a": 1}, max: {"a": 1.5}, hint: {"$**": 1}}),
+ ErrorCodes.BadValue);
+
+ // Throws error for $** index min and max with filter of a different value.
+ assert.commandFailedWithCode(db.runCommand({
+ find: coll.getName(),
+ filter: {"a": 1},
+ min: {"a": 0.5},
+ max: {"a": 1.5},
+ hint: {"$**": 1}
+ }),
+ ErrorCodes.BadValue);
+
+ // Throws error for $** index min with filter of the same value.
+ assert.commandFailedWithCode(
+ db.runCommand(
+ {find: coll.getName(), filter: {"a": 1}, min: {"a": 1}, hint: {"$**": 1}}),
+ ErrorCodes.BadValue);
+
+ // Throws error for $** index max with filter of the same value.
+ assert.commandFailedWithCode(
+ db.runCommand(
+ {find: coll.getName(), filter: {"a": 1}, max: {"a": 1}, hint: {"$**": 1}}),
+ ErrorCodes.BadValue);
+
+ // Throws error for $** index min and max with filter of the same value.
+ assert.commandFailedWithCode(db.runCommand({
+ find: coll.getName(),
+ filter: {"a": 1},
+ min: {"a": 1},
+ max: {"a": 1},
+ hint: {"$**": 1}
+ }),
+ ErrorCodes.BadValue);
+
+ assert.commandWorked(coll.createIndex({"a": 1}));
+
+ // $** index does not interfere with valid min/max.
+ assertArrayEq(coll.find({}, {_id: 0}).min({"a": 0.5}).max({"a": 1.5}).toArray(),
+ [{a: 1, b: 1}, {a: 1, b: 2}]);
+ } finally {
+ // Disable $** indexes once the tests have either completed or failed.
+ db.adminCommand({setParameter: 1, internalQueryAllowAllPathsIndexes: false});
+ }
+})(); \ No newline at end of file