diff options
Diffstat (limited to 'src/mongo/db/catalog/index_key_validate.cpp')
-rw-r--r-- | src/mongo/db/catalog/index_key_validate.cpp | 74 |
1 files changed, 33 insertions, 41 deletions
diff --git a/src/mongo/db/catalog/index_key_validate.cpp b/src/mongo/db/catalog/index_key_validate.cpp index 191194f47f6..2bc450516fb 100644 --- a/src/mongo/db/catalog/index_key_validate.cpp +++ b/src/mongo/db/catalog/index_key_validate.cpp @@ -108,7 +108,7 @@ static const std::set<StringData> allowedIdIndexFieldNames = { IndexDescriptor::kNamespaceFieldName, // Index creation under legacy writeMode can result in an index spec with an _id field. "_id"}; -} +} // namespace Status validateKeyPattern(const BSONObj& key, IndexDescriptor::IndexVersion indexVersion) { const ErrorCodes::Error code = ErrorCodes::CannotCreateIndex; @@ -134,8 +134,7 @@ Status validateKeyPattern(const BSONObj& key, IndexDescriptor::IndexVersion inde if (keyElement.type() == BSONType::Object || keyElement.type() == BSONType::Array) { return {code, str::stream() << "Values in index key pattern cannot be of type " - << typeName(keyElement.type()) - << " for index version v:" + << typeName(keyElement.type()) << " for index version v:" << static_cast<int>(indexVersion)}; } @@ -276,9 +275,9 @@ StatusWith<BSONObj> validateIndexSpec( if (IndexDescriptor::kKeyPatternFieldName == indexSpecElemFieldName) { if (indexSpecElem.type() != BSONType::Object) { return {ErrorCodes::TypeMismatch, - str::stream() << "The field '" << IndexDescriptor::kKeyPatternFieldName - << "' must be an object, but got " - << typeName(indexSpecElem.type())}; + str::stream() + << "The field '" << IndexDescriptor::kKeyPatternFieldName + << "' must be an object, but got " << typeName(indexSpecElem.type())}; } std::vector<StringData> keys; @@ -321,18 +320,18 @@ StatusWith<BSONObj> validateIndexSpec( } else if (IndexDescriptor::kIndexNameFieldName == indexSpecElemFieldName) { if (indexSpecElem.type() != BSONType::String) { return {ErrorCodes::TypeMismatch, - str::stream() << "The field '" << IndexDescriptor::kIndexNameFieldName - << "' must be a string, but got " - << typeName(indexSpecElem.type())}; + str::stream() + << "The field '" << IndexDescriptor::kIndexNameFieldName + << "' must be a string, but got " << typeName(indexSpecElem.type())}; } hasIndexNameField = true; } else if (IndexDescriptor::kNamespaceFieldName == indexSpecElemFieldName) { if (indexSpecElem.type() != BSONType::String) { return {ErrorCodes::TypeMismatch, - str::stream() << "The field '" << IndexDescriptor::kNamespaceFieldName - << "' must be a string, but got " - << typeName(indexSpecElem.type())}; + str::stream() + << "The field '" << IndexDescriptor::kNamespaceFieldName + << "' must be a string, but got " << typeName(indexSpecElem.type())}; } StringData ns = indexSpecElem.valueStringData(); @@ -344,22 +343,19 @@ StatusWith<BSONObj> validateIndexSpec( if (ns != expectedNamespace.ns()) { return {ErrorCodes::BadValue, - str::stream() << "The value of the field '" - << IndexDescriptor::kNamespaceFieldName - << "' (" - << ns - << ") doesn't match the namespace '" - << expectedNamespace - << "'"}; + str::stream() + << "The value of the field '" << IndexDescriptor::kNamespaceFieldName + << "' (" << ns << ") doesn't match the namespace '" << expectedNamespace + << "'"}; } hasNamespaceField = true; } else if (IndexDescriptor::kIndexVersionFieldName == indexSpecElemFieldName) { if (!indexSpecElem.isNumber()) { return {ErrorCodes::TypeMismatch, - str::stream() << "The field '" << IndexDescriptor::kIndexVersionFieldName - << "' must be a number, but got " - << typeName(indexSpecElem.type())}; + str::stream() + << "The field '" << IndexDescriptor::kIndexVersionFieldName + << "' must be a number, but got " << typeName(indexSpecElem.type())}; } auto requestedIndexVersionAsInt = representAs<int>(indexSpecElem.number()); @@ -383,9 +379,9 @@ StatusWith<BSONObj> validateIndexSpec( } else if (IndexDescriptor::kCollationFieldName == indexSpecElemFieldName) { if (indexSpecElem.type() != BSONType::Object) { return {ErrorCodes::TypeMismatch, - str::stream() << "The field '" << IndexDescriptor::kCollationFieldName - << "' must be an object, but got " - << typeName(indexSpecElem.type())}; + str::stream() + << "The field '" << IndexDescriptor::kCollationFieldName + << "' must be an object, but got " << typeName(indexSpecElem.type())}; } if (indexSpecElem.Obj().isEmpty()) { @@ -398,10 +394,9 @@ StatusWith<BSONObj> validateIndexSpec( } else if (IndexDescriptor::kPartialFilterExprFieldName == indexSpecElemFieldName) { if (indexSpecElem.type() != BSONType::Object) { return {ErrorCodes::TypeMismatch, - str::stream() << "The field '" - << IndexDescriptor::kPartialFilterExprFieldName - << "' must be an object, but got " - << typeName(indexSpecElem.type())}; + str::stream() + << "The field '" << IndexDescriptor::kPartialFilterExprFieldName + << "' must be an object, but got " << typeName(indexSpecElem.type())}; } // Just use the simple collator, even though the index may have a separate collation @@ -427,10 +422,9 @@ StatusWith<BSONObj> validateIndexSpec( const auto key = indexSpec.getObjectField(IndexDescriptor::kKeyPatternFieldName); if (IndexNames::findPluginName(key) != IndexNames::WILDCARD) { return {ErrorCodes::BadValue, - str::stream() << "The field '" << IndexDescriptor::kPathProjectionFieldName - << "' is only allowed in an '" - << IndexNames::WILDCARD - << "' index"}; + str::stream() + << "The field '" << IndexDescriptor::kPathProjectionFieldName + << "' is only allowed in an '" << IndexNames::WILDCARD << "' index"}; } if (indexSpecElem.type() != BSONType::Object) { return {ErrorCodes::TypeMismatch, @@ -440,10 +434,10 @@ StatusWith<BSONObj> validateIndexSpec( } if (!key.hasField("$**")) { return {ErrorCodes::FailedToParse, - str::stream() << "The field '" << IndexDescriptor::kPathProjectionFieldName - << "' is only allowed when '" - << IndexDescriptor::kKeyPatternFieldName - << "' is {\"$**\": ±1}"}; + str::stream() + << "The field '" << IndexDescriptor::kPathProjectionFieldName + << "' is only allowed when '" << IndexDescriptor::kKeyPatternFieldName + << "' is {\"$**\": ±1}"}; } if (indexSpecElem.embeddedObject().isEmpty()) { @@ -486,10 +480,8 @@ StatusWith<BSONObj> validateIndexSpec( return {ErrorCodes::CannotCreateIndex, str::stream() << "Invalid index specification " << indexSpec << "; cannot create an index with the '" - << IndexDescriptor::kCollationFieldName - << "' option and " - << IndexDescriptor::kIndexVersionFieldName - << "=" + << IndexDescriptor::kCollationFieldName << "' option and " + << IndexDescriptor::kIndexVersionFieldName << "=" << static_cast<int>(*resolvedIndexVersion)}; } |