diff --git a/jstests/with_mongot/search_mocked/search_error_cases.js b/jstests/with_mongot/search_mocked/search_error_cases.js index 094cdc03cbd..8e61eb1bb51 100644 --- a/jstests/with_mongot/search_mocked/search_error_cases.js +++ b/jstests/with_mongot/search_mocked/search_error_cases.js @@ -60,12 +60,34 @@ assert.commandFailedWithCode( 40602, ); -// $search is not allowed in an update pipeline. Error code matters on version. +// $search is not allowed in an update pipeline. assert.commandFailedWithCode(testDB.runCommand({"findandmodify": collName, "update": [{"$search": {}}]}), [ - 6600901, ErrorCodes.InvalidOptions, ]); +// $search is not allowed in an update command pipeline. +assert.commandFailedWithCode( + testDB.runCommand({ + update: collName, + updates: [{q: {_id: 0}, u: [{$search: {}}]}], + }), + ErrorCodes.InvalidOptions, +); + +// $searchMeta is not allowed in an update pipeline. +assert.commandFailedWithCode(testDB.runCommand({"findandmodify": collName, "update": [{"$searchMeta": {}}]}), [ + ErrorCodes.InvalidOptions, +]); + +// $searchMeta is not allowed in an update command pipeline. +assert.commandFailedWithCode( + testDB.runCommand({ + update: collName, + updates: [{q: {_id: 0}, u: [{$searchMeta: {}}]}], + }), + ErrorCodes.InvalidOptions, +); + // Make sure the server is still up. assert.commandWorked(testDB.runCommand("ping")); diff --git a/src/mongo/db/pipeline/expression_context.h b/src/mongo/db/pipeline/expression_context.h index e46c0c98164..5dd15483cc9 100644 --- a/src/mongo/db/pipeline/expression_context.h +++ b/src/mongo/db/pipeline/expression_context.h @@ -709,14 +709,6 @@ public: _params.isParsingViewDefinition = isParsingViewDefinition; } - bool getIsParsingPipelineUpdate() const { - return _params.isParsingPipelineUpdate; - } - - void setIsParsingPipelineUpdate(bool isParsingPipelineUpdate) { - _params.isParsingPipelineUpdate = isParsingPipelineUpdate; - } - bool getIsParsingCollectionValidator() const { return _params.isParsingCollectionValidator; } @@ -1132,8 +1124,6 @@ protected: bool inUnionWith = false; // True if this ExpressionContext is used to parse a view definition pipeline. bool isParsingViewDefinition = false; - // True if this ExpressionContext is being used to parse an update pipeline. - bool isParsingPipelineUpdate = false; // True if this ExpressionContext is used to parse a collection validator expression. bool isParsingCollectionValidator = false; // These fields can be used in a context when API version validations were not enforced diff --git a/src/mongo/db/pipeline/expression_context_builder.cpp b/src/mongo/db/pipeline/expression_context_builder.cpp index 0c34220feff..feacf006cd0 100644 --- a/src/mongo/db/pipeline/expression_context_builder.cpp +++ b/src/mongo/db/pipeline/expression_context_builder.cpp @@ -174,12 +174,6 @@ ExpressionContextBuilder& ExpressionContextBuilder::isParsingViewDefinition( return *this; } -ExpressionContextBuilder& ExpressionContextBuilder::isParsingPipelineUpdate( - bool isParsingPipelineUpdate) { - params.isParsingPipelineUpdate = isParsingPipelineUpdate; - return *this; -} - ExpressionContextBuilder& ExpressionContextBuilder::isParsingCollectionValidator( bool isParsingCollectionValidator) { params.isParsingCollectionValidator = isParsingCollectionValidator; diff --git a/src/mongo/db/pipeline/expression_context_builder.h b/src/mongo/db/pipeline/expression_context_builder.h index 535ca009bdf..1f8d67468c9 100644 --- a/src/mongo/db/pipeline/expression_context_builder.h +++ b/src/mongo/db/pipeline/expression_context_builder.h @@ -77,7 +77,6 @@ public: ExpressionContextBuilder& inLookup(bool); ExpressionContextBuilder& inUnionWith(bool); ExpressionContextBuilder& isParsingViewDefinition(bool); - ExpressionContextBuilder& isParsingPipelineUpdate(bool); ExpressionContextBuilder& isParsingCollectionValidator(bool); ExpressionContextBuilder& isIdHackQuery(bool); ExpressionContextBuilder& isFleQuery(bool); diff --git a/src/mongo/db/pipeline/search/document_source_search_meta.cpp b/src/mongo/db/pipeline/search/document_source_search_meta.cpp index cf246a306a8..50c02911148 100644 --- a/src/mongo/db/pipeline/search/document_source_search_meta.cpp +++ b/src/mongo/db/pipeline/search/document_source_search_meta.cpp @@ -124,10 +124,6 @@ InternalSearchMongotRemoteSpec prepareInternalSearchMetaMongotSpec( return internalSpec; } - uassert(6600901, - "Running $searchMeta command in non-allowed context (update pipeline)", - !expCtx->getIsParsingPipelineUpdate()); - // If 'searchReturnEofImmediately' is set, we return this stage as is because we don't expect to // return any results. More precisely, we wish to avoid calling 'planShardedSearch' when no // mongot is set up. diff --git a/src/mongo/db/query/write_ops/parsed_update.cpp b/src/mongo/db/query/write_ops/parsed_update.cpp index e203f6cb374..871f6d66353 100644 --- a/src/mongo/db/query/write_ops/parsed_update.cpp +++ b/src/mongo/db/query/write_ops/parsed_update.cpp @@ -139,12 +139,10 @@ void parseUpdate(boost::intrusive_ptr expCtx, ParsedUpdate& p parsedUpdate.driver->setSkipDotsDollarsCheck(true); } - expCtx->setIsParsingPipelineUpdate(true); parsedUpdate.driver->parse(*parsedUpdate.modification, *parsedUpdate.arrayFilters, parsedUpdate.request->getUpdateConstants(), parsedUpdate.request->isMulti()); - expCtx->setIsParsingPipelineUpdate(false); } /**