From 776fa925589a76dbd5c55416bc2cd1744e937a6d Mon Sep 17 00:00:00 2001 From: madelinezec <15312869+madelinezec@users.noreply.github.com> Date: Fri, 1 Nov 2024 15:57:29 -0400 Subject: [PATCH] SERVER-96513 address todo from lookup.search ticket (#28763) GitOrigin-RevId: ea618a4a0cf2abaf45a3f2106b855662fd2683a0 --- jstests/with_mongot/e2e/views/storedSource.js | 101 +++++++++--------- src/mongo/db/views/view_catalog_helpers.cpp | 3 +- 2 files changed, 51 insertions(+), 53 deletions(-) diff --git a/jstests/with_mongot/e2e/views/storedSource.js b/jstests/with_mongot/e2e/views/storedSource.js index e08fb8f12e5..3e1dd740ffc 100644 --- a/jstests/with_mongot/e2e/views/storedSource.js +++ b/jstests/with_mongot/e2e/views/storedSource.js @@ -97,58 +97,57 @@ let expectedResults = [ ]; let results = addFieldsView.aggregate(pipeline).toArray(); assertArrayEq({actual: results, expected: expectedResults}); -// TODO SERVER-93638 uncomment rest of test when $lookup.search on views support is enabled. -// // Make sure if storedSource query is part of a inner subpipeline, the view transforms aren't -// // applied by mongod. -// const baseColl = testDb.baseColl; -// baseColl.drop(); -// assert.commandWorked( -// baseColl.insertMany([{state: "AK"}, {state: "CA"}, {state: "NY"}, {state: "NJ"}])); -// let storedSourceAsSubPipe = [ -// { -// $lookup: { -// from: viewName, -// localField: "state", -// foreignField: "state", -// as: "state_facts", -// pipeline -// } -// }, {$project: {_id: 0, "state_facts.state": 0}} -// ]; -// explain = baseColl.explain().aggregate(storedSourceAsSubPipe); -// assertViewNotApplied(explain.stages, viewPipeline); +// Make sure if storedSource query is part of a inner subpipeline, the view transforms aren't +// applied by mongod. +const baseColl = testDb.baseColl; +baseColl.drop(); +assert.commandWorked( + baseColl.insertMany([{state: "AK"}, {state: "CA"}, {state: "NY"}, {state: "NJ"}])); -// expectedResults = [ -// { -// state: "AK", -// state_facts: -// [{pop: 3000000, facts: {state_motto: "Regnat Populus", official_state_colors: []}}] -// }, -// { -// state: "CA", -// state_facts: [ -// {pop: 39000000, -// facts: {state_motto: "Eureka", official_state_colors: ["blue", "gold"]}} -// ] -// }, -// { -// state: "NY", -// state_facts: [{pop: 19000000, facts: {state_motto: "Excelsior", official_state_colors: -// []}}] -// }, -// { -// state: "NJ", -// state_facts: [{ -// pop: 9000000, -// facts: { -// state_motto: "Liberty and Prosperity", -// official_state_colors: ["jersey blue", "bluff"] -// } -// }] -// } -// ]; -// results = baseColl.aggregate(storedSourceAsSubPipe).toArray(); -// assertArrayEq({actual: results, expected: expectedResults}); +let storedSourceAsSubPipe = [ + { + $lookup: { + from: viewName, + localField: "state", + foreignField: "state", + as: "state_facts", + pipeline + } + }, {$project: {_id: 0, "state_facts.state": 0}} +]; +explain = baseColl.explain().aggregate(storedSourceAsSubPipe); +assertViewNotApplied(explain.stages, viewPipeline); + +expectedResults = [ + { + state: "AK", + state_facts: + [{pop: 3000000, facts: {state_motto: "Regnat Populus", official_state_colors: []}}] + }, + { + state: "CA", + state_facts: [ + {pop: 39000000, + facts: {state_motto: "Eureka", official_state_colors: ["blue", "gold"]}} + ] + }, + { + state: "NY", + state_facts: [{pop: 19000000, facts: {state_motto: "Excelsior", official_state_colors: []}}] + }, + { + state: "NJ", + state_facts: [{ + pop: 9000000, + facts: { + state_motto: "Liberty and Prosperity", + official_state_colors: ["jersey blue", "bluff"] + } + }] + } +]; +results = baseColl.aggregate(storedSourceAsSubPipe).toArray(); +assertArrayEq({actual: results, expected: expectedResults}); dropSearchIndex(addFieldsView, {name: "storedSourceIx"}); \ No newline at end of file diff --git a/src/mongo/db/views/view_catalog_helpers.cpp b/src/mongo/db/views/view_catalog_helpers.cpp index 8ff78c9c3d7..eb0ad9a6fc3 100644 --- a/src/mongo/db/views/view_catalog_helpers.cpp +++ b/src/mongo/db/views/view_catalog_helpers.cpp @@ -156,8 +156,7 @@ StatusWith> validatePipeline(OperationConte return liteParsedPipeline.getInvolvedNamespaces(); } -// TODO SERVER-93638 add comment for expected behavior of $lookup/$unionWith which might have -// multiple backing collections. + NamespaceString findSourceCollectionNamespace(OperationContext* opCtx, std::shared_ptr catalog, const NamespaceString& nss) {