summaryrefslogtreecommitdiff
path: root/src/mongo/db/pipeline/document_source_union_with.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/mongo/db/pipeline/document_source_union_with.h')
-rw-r--r--src/mongo/db/pipeline/document_source_union_with.h17
1 files changed, 15 insertions, 2 deletions
diff --git a/src/mongo/db/pipeline/document_source_union_with.h b/src/mongo/db/pipeline/document_source_union_with.h
index 0bf34dbf376..ba0327a4be2 100644
--- a/src/mongo/db/pipeline/document_source_union_with.h
+++ b/src/mongo/db/pipeline/document_source_union_with.h
@@ -58,7 +58,19 @@ public:
DocumentSourceUnionWith(const boost::intrusive_ptr<ExpressionContext>& expCtx,
std::unique_ptr<Pipeline, PipelineDeleter> pipeline)
- : DocumentSource(kStageName, expCtx), _pipeline(std::move(pipeline)) {}
+ : DocumentSource(kStageName, expCtx), _pipeline(std::move(pipeline)) {
+ if (_pipeline) {
+ const auto& sources = _pipeline->getSources();
+ auto it = std::find_if(sources.begin(), sources.end(), [](const auto& src) {
+ return !src->constraints().isAllowedInUnionPipeline();
+ });
+
+ uassert(31441,
+ str::stream() << (*it)->getSourceName()
+ << " is not allowed within a $unionWith's sub-pipeline",
+ it == sources.end());
+ }
+ }
const char* getSourceName() const final {
return kStageName.rawData();
@@ -80,7 +92,8 @@ public:
TransactionRequirement::kNotAllowed,
// The check to disallow $unionWith on a sharded collection within $lookup happens
// outside of the constraints as long as the involved namespaces are reported correctly.
- LookupRequirement::kAllowed);
+ LookupRequirement::kAllowed,
+ UnionRequirement::kAllowed);
}
DepsTracker::State getDependencies(DepsTracker* deps) const final;