diff options
Diffstat (limited to 'src/mongo/db/catalog')
-rw-r--r-- | src/mongo/db/catalog/index_key_validate.cpp | 3 | ||||
-rw-r--r-- | src/mongo/db/catalog/index_spec_validate_test.cpp | 25 |
2 files changed, 26 insertions, 2 deletions
diff --git a/src/mongo/db/catalog/index_key_validate.cpp b/src/mongo/db/catalog/index_key_validate.cpp index ca5ac2aaea5..4c1695069d5 100644 --- a/src/mongo/db/catalog/index_key_validate.cpp +++ b/src/mongo/db/catalog/index_key_validate.cpp @@ -133,7 +133,8 @@ Status validateKeyPattern(const BSONObj& key, IndexDescriptor::IndexVersion inde break; } - case IndexVersion::kV2: { + case IndexVersion::kV2: + case IndexVersion::kV2Unique: { if (keyElement.isNumber()) { double value = keyElement.number(); if (std::isnan(value)) { diff --git a/src/mongo/db/catalog/index_spec_validate_test.cpp b/src/mongo/db/catalog/index_spec_validate_test.cpp index f0107cff856..471f1a525ca 100644 --- a/src/mongo/db/catalog/index_spec_validate_test.cpp +++ b/src/mongo/db/catalog/index_spec_validate_test.cpp @@ -299,7 +299,7 @@ TEST(IndexSpecValidateTest, ReturnsAnErrorIfVersionIsUnsupported) { BSON("key" << BSON("field" << 1) << "name" << "indexName" << "v" - << 3 + << 4 << "collation" << BSON("locale" << "en")), @@ -398,6 +398,29 @@ TEST(IndexSpecValidateTest, AcceptsIndexVersionV1) { sorted(result.getValue())); } +TEST(IndexSpecValidateTest, AcceptsIndexVersionV2Unique) { + ServerGlobalParams::FeatureCompatibility featureCompatibility; + featureCompatibility.setVersion( + ServerGlobalParams::FeatureCompatibility::Version::kFullyUpgradedTo36); + + auto result = validateIndexSpec(kDefaultOpCtx, + BSON("key" << BSON("field" << 1) << "name" + << "indexName" + << "v" + << 3), + kTestNamespace, + featureCompatibility); + ASSERT_OK(result.getStatus()); + + // We don't care about the order of the fields in the resulting index specification. + ASSERT_BSONOBJ_EQ(sorted(BSON("key" << BSON("field" << 1) << "name" + << "indexName" + << "ns" + << kTestNamespace.ns() + << "v" + << 3)), + sorted(result.getValue())); +} TEST(IndexSpecValidateTest, ReturnsAnErrorIfCollationIsNotAnObject) { ASSERT_EQ(ErrorCodes::TypeMismatch, validateIndexSpec(kDefaultOpCtx, |