From d45258b1e76642f14c7a60b1a6c3bb9596cf5ae6 Mon Sep 17 00:00:00 2001 From: Arun Banala Date: Wed, 30 Oct 2019 13:18:39 +0000 Subject: SERVER-44050 Arrays are not correctly rejected during key generation for 'hashed' indexes (cherry picked from commit 888f7e6fc10ccb999be203b8cbad4dbe19d0a5d2) (cherry picked from commit ffda4b8dd699251f487596ff008133830a5ec392) (cherry picked from commit ca240d5215ed88ad874c5355528710fb9d3eff37) --- jstests/core/hashindex1.js | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'jstests') diff --git a/jstests/core/hashindex1.js b/jstests/core/hashindex1.js index 24949789c5f..fc1f14697a4 100644 --- a/jstests/core/hashindex1.js +++ b/jstests/core/hashindex1.js @@ -92,3 +92,13 @@ var total = t.find().hint({"_id": 1}).toArray().length; var totala = t.find().hint(goodspec).toArray().length; assert.eq(total, totala, "non-sparse index has wrong total"); assert.lt(totalb, totala, "sparse index should have smaller total"); + +// Test that having arrays along the path of the index is not allowed. +assert.commandWorked(t.createIndex({"field1.field2.0.field4": "hashed"})); +assert.writeErrorWithCode(t.insert({field1: []}), 16766); +assert.writeErrorWithCode(t.insert({field1: {field2: []}}), 16766); +assert.writeErrorWithCode(t.insert({field1: {field2: {0: []}}}), 16766); +assert.writeErrorWithCode(t.insert({field1: [{field2: {0: []}}]}), 16766); +assert.writeErrorWithCode(t.insert({field1: {field2: {0: {field4: []}}}}), 16766); +assert.writeOK(t.insert({field1: {field2: {0: {otherField: []}}}})); +assert.writeOK(t.insert({field1: {field2: {0: {field4: 1}}}})); -- cgit v1.2.1