summaryrefslogtreecommitdiff
path: root/jstests/core/index/indexp.js
diff options
context:
space:
mode:
Diffstat (limited to 'jstests/core/index/indexp.js')
-rw-r--r--jstests/core/index/indexp.js23
1 files changed, 23 insertions, 0 deletions
diff --git a/jstests/core/index/indexp.js b/jstests/core/index/indexp.js
new file mode 100644
index 00000000000..8199e0f132c
--- /dev/null
+++ b/jstests/core/index/indexp.js
@@ -0,0 +1,23 @@
+// Tests that SERVER-11374 is fixed: specifically, that indexes cannot
+// be created on fields that begin with '$' but are not part of DBRefs
+// and that indexes cannot be created on field paths that contain empty
+// fields.
+
+var coll = db.jstests_indexp;
+
+// Empty field checks.
+assert.commandFailed(coll.createIndex({'a..b': 1}));
+assert.commandFailed(coll.createIndex({'.a': 1}));
+assert.commandFailed(coll.createIndex({'a.': 1}));
+assert.commandFailed(coll.createIndex({'.': 1}));
+assert.commandFailed(coll.createIndex({'': 1}));
+assert.commandWorked(coll.createIndex({'a.b': 1}));
+
+// '$'-prefixed field checks.
+assert.commandFailed(coll.createIndex({'$a': 1}));
+assert.commandFailed(coll.createIndex({'a.$b': 1}));
+assert.commandFailed(coll.createIndex({'$db': 1}));
+assert.commandWorked(coll.createIndex({'a$ap': 1})); // $ in middle is ok
+assert.commandWorked(coll.createIndex({'a.$id': 1})); // $id/$db/$ref are execptions
+
+coll.dropIndexes();