diff --git a/src/mongo/db/pipeline/search/search_helper_bson_obj.h b/src/mongo/db/pipeline/search/search_helper_bson_obj.h index e31d2bff122..b14aaa1ad55 100644 --- a/src/mongo/db/pipeline/search/search_helper_bson_obj.h +++ b/src/mongo/db/pipeline/search/search_helper_bson_obj.h @@ -61,6 +61,32 @@ inline bool hasMongotExtension(const auto& extensionNames) { } // namespace detail +/** + * Checks that the pipeline isn't empty and if the first stage in the pipeline is the $vectorSearch + * extension stage. The legacy stage returns false. + * + * TODO SERVER-117168 Remove this function. + */ +inline bool isExtensionVectorSearchPipeline( + const std::shared_ptr& ifrContext, + const std::vector& pipeline) { + if (pipeline.empty()) { + return false; + } + const auto& firstStageBson = pipeline[0]; + using detail::is; + if (is(firstStageBson)) { + // Note we don't need to worry about/consult 'featureFlagExtensionViewsAndUnionWith' + // because the extension will enforce this behavior by toggling + // 'gFeatureFlagVectorSearchExtension' and retrying, so thankfully this is enough, and + // we don't need to understand what context this BSON appears in (w.r.t. views or + // sub-pipelines). + return ifrContext->getSavedFlagValue(feature_flags::gFeatureFlagVectorSearchExtension) && + detail::hasMongotExtension(serverGlobalParams.extensions); + } + return false; +} + /** * Checks that the pipeline isn't empty and if the first stage in the pipeline is a mongot stage * Namely, that includes: diff --git a/src/mongo/db/views/pipeline_resolver.cpp b/src/mongo/db/views/pipeline_resolver.cpp index 9a1719470a4..2acd9fa1ad9 100644 --- a/src/mongo/db/views/pipeline_resolver.cpp +++ b/src/mongo/db/views/pipeline_resolver.cpp @@ -71,7 +71,8 @@ std::vector buildResolvedPipelineForSimpleCase( // Mongot user pipelines are a unique case: $_internalSearchIdLookup applies the view pipeline. // For this reason, we do not expand the aggregation request to include the view pipeline. // Caller is expected to use LiteParsedPipeline::handleView() for such cases. - if (search_helper_bson_obj::isMongotPipeline(ifrContext, userPipeline)) { + if (search_helper_bson_obj::isMongotPipeline(ifrContext, userPipeline) || + search_helper_bson_obj::isExtensionVectorSearchPipeline(ifrContext, userPipeline)) { return userPipeline; }