diff options
author | Charlie Swanson <charlie.swanson@mongodb.com> | 2019-02-06 12:23:23 -0500 |
---|---|---|
committer | Charlie Swanson <charlie.swanson@mongodb.com> | 2019-02-14 16:54:47 -0500 |
commit | f1da8170c1c568762b29e44910afbcc6f01a644f (patch) | |
tree | 6c45403feafcc9748500bb809cb0d7c5a6ce19de /src/mongo/db/pipeline/document_source_graph_lookup.cpp | |
parent | b494c59557d464d1e13f7c36e7148b48e4d87208 (diff) | |
download | mongo-f1da8170c1c568762b29e44910afbcc6f01a644f.tar.gz |
SERVER-38360 Prevent $out writing to ns read from in the same pipeline
This restriction only applies to $out with modes "insertDocuments" and
"replaceDocuments".
Diffstat (limited to 'src/mongo/db/pipeline/document_source_graph_lookup.cpp')
-rw-r--r-- | src/mongo/db/pipeline/document_source_graph_lookup.cpp | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/src/mongo/db/pipeline/document_source_graph_lookup.cpp b/src/mongo/db/pipeline/document_source_graph_lookup.cpp index ee745dedda6..eea8b370cdf 100644 --- a/src/mongo/db/pipeline/document_source_graph_lookup.cpp +++ b/src/mongo/db/pipeline/document_source_graph_lookup.cpp @@ -476,7 +476,7 @@ DocumentSourceGraphLookUp::DocumentSourceGraphLookUp( // We append an additional BSONObj to '_fromPipeline' as a placeholder for the $match stage // we'll eventually construct from the input document. _fromPipeline.reserve(_fromPipeline.size() + 1); - _fromPipeline.push_back(BSONObj()); + _fromPipeline.push_back(BSON("$match" << BSONObj())); } intrusive_ptr<DocumentSourceGraphLookUp> DocumentSourceGraphLookUp::create( @@ -602,4 +602,13 @@ intrusive_ptr<DocumentSource> DocumentSourceGraphLookUp::createFromBson( return std::move(newSource); } + +void DocumentSourceGraphLookUp::addInvolvedCollections( + stdx::unordered_set<NamespaceString>* collectionNames) const { + collectionNames->insert(_fromExpCtx->ns); + auto introspectionPipeline = uassertStatusOK(Pipeline::parse(_fromPipeline, _fromExpCtx)); + for (auto&& stage : introspectionPipeline->getSources()) { + stage->addInvolvedCollections(collectionNames); + } +} } // namespace mongo |