diff options
Diffstat (limited to 'src/mongo/db/index/expression_params.cpp')
-rw-r--r-- | src/mongo/db/index/expression_params.cpp | 21 |
1 files changed, 16 insertions, 5 deletions
diff --git a/src/mongo/db/index/expression_params.cpp b/src/mongo/db/index/expression_params.cpp index 4dc0ebbb8d9..29977a5baab 100644 --- a/src/mongo/db/index/expression_params.cpp +++ b/src/mongo/db/index/expression_params.cpp @@ -72,7 +72,7 @@ void ExpressionParams::parseTwoDParams(const BSONObj& infoObj, TwoDIndexingParam void ExpressionParams::parseHashParams(const BSONObj& infoObj, HashSeed* seedOut, int* versionOut, - std::string* fieldOut) { + BSONObj* keyPattern) { // Default _seed to DEFAULT_HASH_SEED if "seed" is not included in the index spec // or if the value of "seed" is not a number @@ -91,10 +91,21 @@ void ExpressionParams::parseHashParams(const BSONObj& infoObj, // the value of "hashversion" is not a number *versionOut = infoObj["hashVersion"].numberInt(); - // Get the hashfield name - BSONElement firstElt = infoObj.getObjectField("key").firstElement(); - massert(16765, "error: no hashed index field", firstElt.str().compare(IndexNames::HASHED) == 0); - *fieldOut = firstElt.fieldName(); + // Extract and validate the index key pattern + int numHashFields = 0; + *keyPattern = infoObj.getObjectField("key"); + for (auto&& indexField : *keyPattern) { + // The 'indexField' can either be ascending (1), descending (-1), or HASHED. Any other field + // types should have failed validation while parsing. + invariant(indexField.isNumber() || (indexField.valueStringData() == IndexNames::HASHED)); + numHashFields += (indexField.isNumber()) ? 0 : 1; + } + // We shouldn't be here if there are no hashed fields in the index. + invariant(numHashFields > 0); + uassert(31303, + str::stream() << "A maximum of one index field is allowed to be hashed but found " + << numHashFields << " for 'key' " << *keyPattern, + numHashFields == 1); } void ExpressionParams::parseHaystackParams(const BSONObj& infoObj, |