summaryrefslogtreecommitdiff
path: root/jstests/core/index_bigkeys_validation.js
diff options
context:
space:
mode:
Diffstat (limited to 'jstests/core/index_bigkeys_validation.js')
-rw-r--r--jstests/core/index_bigkeys_validation.js28
1 files changed, 28 insertions, 0 deletions
diff --git a/jstests/core/index_bigkeys_validation.js b/jstests/core/index_bigkeys_validation.js
new file mode 100644
index 00000000000..88e2816fc8d
--- /dev/null
+++ b/jstests/core/index_bigkeys_validation.js
@@ -0,0 +1,28 @@
+// Tests that index validation succeeds for long keys when failIndexKeyTooLong is set to false.
+// See: SERVER-22234
+'use strict';
+
+(function() {
+ var coll = db.longindex;
+ coll.drop();
+
+ var longVal = new Array(1025).join('x'); // Keys >= 1024 bytes cannot be indexed.
+
+ assert.commandWorked(db.adminCommand({setParameter: 1, failIndexKeyTooLong: false}));
+
+ assert.writeOK(coll.insert({_id: longVal}));
+ // Verify that validation succeeds when the failIndexKeyTooLong parameter is set to false,
+ // even when there are fewer index keys than documents.
+ var res = coll.validate({full: true, scandata: true});
+ assert.commandWorked(res);
+ assert(res.valid, tojson(res));
+
+ // Change failIndexKeyTooLong back to the default value.
+ assert.commandWorked(db.adminCommand({setParameter: 1, failIndexKeyTooLong: true}));
+
+ // Verify that validation fails when the failIndexKeyTooLong parameter is
+ // reverted to its old value and there are mismatched index keys and documents.
+ res = coll.validate({full: true, scandata: true});
+ assert.commandWorked(res);
+ assert.eq(res.valid, false, tojson(res));
+})();