summaryrefslogtreecommitdiff
path: root/src/mongo/db/index
diff options
context:
space:
mode:
authorArun Banala <arun.banala@10gen.com>2019-10-29 13:14:00 +0000
committerevergreen <evergreen@mongodb.com>2019-10-29 13:14:00 +0000
commitc2f71b097c9d452dcec235725cf4b5e391ef4e56 (patch)
tree1a0ff0cea3e742ce305383a5e1bb373cdfc82a95 /src/mongo/db/index
parent4e6213ae16547d97af8a7b5f99e17e9d215c9bc2 (diff)
downloadmongo-c2f71b097c9d452dcec235725cf4b5e391ef4e56.tar.gz
SERVER-44050 Arrays are not correctly rejected during key generation for 'hashed' indexes
(cherry picked from commit 888f7e6fc10ccb999be203b8cbad4dbe19d0a5d2)
Diffstat (limited to 'src/mongo/db/index')
-rw-r--r--src/mongo/db/index/expression_keys_private.cpp20
1 files changed, 12 insertions, 8 deletions
diff --git a/src/mongo/db/index/expression_keys_private.cpp b/src/mongo/db/index/expression_keys_private.cpp
index 11ed573f27f..cd170c24819 100644
--- a/src/mongo/db/index/expression_keys_private.cpp
+++ b/src/mongo/db/index/expression_keys_private.cpp
@@ -346,7 +346,18 @@ void ExpressionKeysPrivate::getHashKeys(const BSONObj& obj,
const CollatorInterface* collator,
BSONObjSet* keys) {
const char* cstr = hashedField.c_str();
- BSONElement fieldVal = dps::extractElementAtPath(obj, cstr);
+ BSONElement fieldVal = dps::extractElementAtPathOrArrayAlongPath(obj, cstr);
+
+ // If we hit an array while traversing the path, 'cstr' will point to the path component
+ // immediately following the array, or the null termination byte if the final field in the path
+ // was an array.
+ uassert(
+ 16766,
+ str::stream()
+ << "Error: hashed indexes do not currently support array values. Found array at path: "
+ << hashedField.substr(
+ 0, hashedField.size() - StringData(cstr).size() - !StringData(cstr).empty()),
+ fieldVal.type() != BSONType::Array);
// Convert strings to comparison keys.
BSONObj fieldValObj;
@@ -355,13 +366,6 @@ void ExpressionKeysPrivate::getHashKeys(const BSONObj& obj,
CollationIndexKey::collationAwareIndexKeyAppend(fieldVal, collator, &bob);
fieldValObj = bob.obj();
fieldVal = fieldValObj.firstElement();
- }
-
- uassert(16766,
- "Error: hashed indexes do not currently support array values",
- fieldVal.type() != Array);
-
- if (!fieldVal.eoo()) {
BSONObj key = BSON("" << makeSingleHashKey(fieldVal, seed, hashVersion));
keys->insert(key);
} else if (!isSparse) {