summaryrefslogtreecommitdiff
path: root/src/mongo/db/pipeline/document_source_out_replace_coll.cpp
diff options
context:
space:
mode:
authorDianna Hohensee <dianna.hohensee@10gen.com>2018-08-16 15:48:39 -0400
committerDianna Hohensee <dianna.hohensee@10gen.com>2018-08-23 16:22:09 -0400
commit5ddf4d517a45229f9b395186e5e4bba7e9636fdc (patch)
tree4054e8b03cb894f93021185202d0d2f774a43eb3 /src/mongo/db/pipeline/document_source_out_replace_coll.cpp
parent078d6b49548d90880556af6f55e3baf8b4709917 (diff)
downloadmongo-5ddf4d517a45229f9b395186e5e4bba7e9636fdc.tar.gz
SERVER-36714 update DocumentSourceOutReplaceColl::initializeWriteNs to use createIndexes rather than a system.indexes insert
Diffstat (limited to 'src/mongo/db/pipeline/document_source_out_replace_coll.cpp')
-rw-r--r--src/mongo/db/pipeline/document_source_out_replace_coll.cpp30
1 files changed, 15 insertions, 15 deletions
diff --git a/src/mongo/db/pipeline/document_source_out_replace_coll.cpp b/src/mongo/db/pipeline/document_source_out_replace_coll.cpp
index 7b0ab47f256..c351e222a7b 100644
--- a/src/mongo/db/pipeline/document_source_out_replace_coll.cpp
+++ b/src/mongo/db/pipeline/document_source_out_replace_coll.cpp
@@ -74,22 +74,22 @@ void DocumentSourceOutReplaceColl::initializeWriteNs() {
conn->runCommand(outputNs.db().toString(), cmd.done(), info));
}
+ if (_originalIndexes.empty()) {
+ return;
+ }
+
// Copy the indexes of the output collection to the temp collection.
- for (auto indexSpec : _originalIndexes) {
- MutableDocument index((Document(indexSpec)));
- index.remove("_id"); // indexes shouldn't have _ids but some existing ones do
- index["ns"] = Value(_tempNs.ns());
-
- BSONObj indexBson = index.freeze().toBson();
- conn->insert(_tempNs.getSystemIndexesCollection(), indexBson);
- BSONObj err = conn->getLastErrorDetailed();
- uassert(16995,
- str::stream() << "copying index for $out failed."
- << " index: "
- << indexBson
- << " error: "
- << err,
- DBClientBase::getLastErrorString(err).empty());
+ std::vector<BSONObj> tempNsIndexes;
+ for (const auto& indexSpec : _originalIndexes) {
+ // Replace the spec's 'ns' field value, which is the original collection, with the temp
+ // collection.
+ tempNsIndexes.push_back(indexSpec.addField(BSON("ns" << _tempNs.ns()).firstElement()));
+ }
+ try {
+ conn->createIndexes(_tempNs.ns(), tempNsIndexes);
+ } catch (DBException& ex) {
+ ex.addContext("Copying indexes for $out failed");
+ throw;
}
};