summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGregory Wlodarek <gregory.wlodarek@mongodb.com>2019-07-17 11:43:41 -0400
committerGregory Wlodarek <gregory.wlodarek@mongodb.com>2019-07-17 15:37:05 -0400
commit054a361cfc6f435a5d0417361874f1eeb880088d (patch)
tree232d0da3f8a647b2e97a132acf1e00848220a165
parent7f56158f69facfc1b1504d62876d7f6f11848297 (diff)
downloadmongo-r4.2.0-rc3.tar.gz
SERVER-42260 IndexCatalog should add the 'ns' field to the index spec if it's missingr4.2.0-rc3
-rw-r--r--src/mongo/db/catalog/index_catalog_impl.cpp15
-rw-r--r--src/mongo/db/index/index_descriptor.cpp3
2 files changed, 12 insertions, 6 deletions
diff --git a/src/mongo/db/catalog/index_catalog_impl.cpp b/src/mongo/db/catalog/index_catalog_impl.cpp
index ac6a49d7fba..670622a17be 100644
--- a/src/mongo/db/catalog/index_catalog_impl.cpp
+++ b/src/mongo/db/catalog/index_catalog_impl.cpp
@@ -552,13 +552,12 @@ Status IndexCatalogImpl::_isSpecOk(OperationContext* opCtx, const BSONObj& spec)
if (nss.isOplog())
return Status(ErrorCodes::CannotCreateIndex, "cannot have an index on the oplog");
- // If we stop generating the 'ns' field for index specs during testing, then we shouldn't
- // validate that the 'ns' field is missing.
- if (!disableIndexSpecNamespaceGeneration.load()) {
+ // If the index spec has the 'ns' field and if we don't stop generating the 'ns' field during
+ // testing, validate that it is correct.
+ if (spec.hasField("ns") && !disableIndexSpecNamespaceGeneration.load()) {
const BSONElement specNamespace = spec["ns"];
if (specNamespace.type() != String)
- return Status(ErrorCodes::CannotCreateIndex,
- "the index spec is missing a \"ns\" string field");
+ return Status(ErrorCodes::CannotCreateIndex, "the \"ns\" field is not a string");
if (nss.ns() != specNamespace.valueStringData())
return Status(ErrorCodes::CannotCreateIndex,
@@ -1720,6 +1719,12 @@ StatusWith<BSONObj> IndexCatalogImpl::_fixIndexSpec(OperationContext* opCtx,
}
b.append("name", name);
+ // The 'ns' field was removed from index specs in v4.4 and could be missing when running with
+ // mixed version nodes.
+ if (!spec.hasField("ns") && !disableIndexSpecNamespaceGeneration.load()) {
+ b.append("ns", collection->ns().ns());
+ }
+
{
BSONObjIterator i(o);
while (i.more()) {
diff --git a/src/mongo/db/index/index_descriptor.cpp b/src/mongo/db/index/index_descriptor.cpp
index edae421b9f6..e400c3c0df2 100644
--- a/src/mongo/db/index/index_descriptor.cpp
+++ b/src/mongo/db/index/index_descriptor.cpp
@@ -62,7 +62,8 @@ void populateOptionsMap(std::map<StringData, BSONElement>& theMap, const BSONObj
IndexDescriptor::kBackgroundFieldName || // this is a creation time option only
fieldName == IndexDescriptor::kDropDuplicatesFieldName || // this is now ignored
fieldName == IndexDescriptor::kSparseFieldName || // checked specially
- fieldName == IndexDescriptor::kUniqueFieldName // check specially
+ fieldName == IndexDescriptor::kUniqueFieldName || // check specially
+ fieldName == IndexDescriptor::kNamespaceFieldName // removed in 4.4
) {
continue;
}