diff options
author | David Storch <david.storch@10gen.com> | 2018-10-04 18:27:48 -0400 |
---|---|---|
committer | David Storch <david.storch@10gen.com> | 2018-10-23 17:18:11 -0400 |
commit | 2cdc2a96e1c8779658fe0eab459dcc38cf01c54d (patch) | |
tree | 875f55acaaba283f02895938ee4b6c764eac349a /src/mongo/db/index/index_descriptor.cpp | |
parent | e7bed9bdcb376d5a06dce6228047309e8481f9cf (diff) | |
download | mongo-2cdc2a96e1c8779658fe0eab459dcc38cf01c54d.tar.gz |
SERVER-37443 Make catalog objects survive collection rename.
This change only applies to collection renames within the
same database. Rename across databases requires copying the
data, and the resulting collection will have a new UUID.
Diffstat (limited to 'src/mongo/db/index/index_descriptor.cpp')
-rw-r--r-- | src/mongo/db/index/index_descriptor.cpp | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/src/mongo/db/index/index_descriptor.cpp b/src/mongo/db/index/index_descriptor.cpp index ad2dca4237e..bf94a32542d 100644 --- a/src/mongo/db/index/index_descriptor.cpp +++ b/src/mongo/db/index/index_descriptor.cpp @@ -172,4 +172,25 @@ bool IndexDescriptor::areIndexOptionsEquivalent(const IndexDescriptor* other) co rhs.second); }); } + +void IndexDescriptor::setNs(NamespaceString ns) { + _parentNS = ns.toString(); + _indexNamespace = makeIndexNamespace(_parentNS, _indexName); + + // Construct a new infoObj with the namespace field replaced. + _infoObj = renameNsInIndexSpec(_infoObj, ns); } + +BSONObj IndexDescriptor::renameNsInIndexSpec(BSONObj spec, const NamespaceString& newNs) { + BSONObjBuilder builder; + for (auto&& elt : spec) { + if (elt.fieldNameStringData() == kNamespaceFieldName) { + builder.append(kNamespaceFieldName, newNs.ns()); + } else { + builder.append(elt); + } + } + return builder.obj(); +} + +} // namespace mongo |