From bb9114dc71bfcf42422471f7789eca00881b8864 Mon Sep 17 00:00:00 2001 From: Brigitte Lamarche Date: Thu, 20 Dec 2018 14:24:02 -0500 Subject: SERVER-38362 Prevent $out stage within $lookup --- src/mongo/db/pipeline/document_source_lookup.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'src/mongo/db/pipeline/document_source_lookup.cpp') diff --git a/src/mongo/db/pipeline/document_source_lookup.cpp b/src/mongo/db/pipeline/document_source_lookup.cpp index 84ff4c5496e..0d8ea164537 100644 --- a/src/mongo/db/pipeline/document_source_lookup.cpp +++ b/src/mongo/db/pipeline/document_source_lookup.cpp @@ -656,8 +656,14 @@ void DocumentSourceLookUp::initializeIntrospectionPipeline() { // Ensure that the pipeline does not contain a $changeStream stage. This check will be // performed recursively on all sub-pipelines. uassert(ErrorCodes::IllegalOperation, - "$changeStream is not allowed within a $lookup foreign pipeline", + "$changeStream is not allowed within a $lookup's pipeline", sources.empty() || !sources.front()->constraints().isChangeStreamStage()); + + // Ensure that the pipeline does not contain a $out stage. Since $out must be the last stage + // of a pipeline, we only need to check the last DocumentSource. + uassert(51047, + "$out is not allowed within a $lookup's pipeline", + sources.empty() || !sources.back()->constraints().writesPersistentData()); } void DocumentSourceLookUp::serializeToArray( -- cgit v1.2.1