CSHARP-5769: Implement hasAncestor, hasRoot, and returnScope for Atlas Search#1933
Draft
ajcvickers wants to merge 1 commit intomongodb:mainfrom
Draft
CSHARP-5769: Implement hasAncestor, hasRoot, and returnScope for Atlas Search#1933ajcvickers wants to merge 1 commit intomongodb:mainfrom
ajcvickers wants to merge 1 commit intomongodb:mainfrom
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR extends the driver’s Atlas Search support by adding hasAncestor/hasRoot operators (for embedded document queries) and returnScope support for $search / $searchMeta, including option cloning to prevent mutating caller-provided SearchOptions when returnScope is set.
Changes:
- Add
HasAncestorandHasRootsearch operators and rendering support. - Add
returnScopeoverloads for$searchand$searchMetaacross pipeline + fluent APIs. - Introduce
Clone()onSearchOptionsand nested option classes; add/extend Atlas Search tests and utilities.
Reviewed changes
Copilot reviewed 18 out of 18 changed files in this pull request and generated 7 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/MongoDB.Driver.Tests/Search/VectorSearchTests.cs | Update test client creation to match new tuple-returning helper. |
| tests/MongoDB.Driver.Tests/Search/SearchDefinitionBuilderTests.cs | Add rendering tests for HasAncestor / HasRoot. |
| tests/MongoDB.Driver.Tests/Search/AutoEmbedVectorSearchTests.cs | Update test client creation to match new tuple-returning helper. |
| tests/MongoDB.Driver.Tests/Search/AtlasSearchTestsUtils.cs | Return (IMongoClient, EventCapturer) and configure command capture for aggregates. |
| tests/MongoDB.Driver.Tests/Search/AtlasSearchTests.cs | Add integration tests for HasAncestor/HasRoot in embeddedDocument and for returnScope in $search/$searchMeta; add test data/index setup and captured-stage validation. |
| src/MongoDB.Driver/Search/SearchTrackingOptions.cs | Add Clone() to support safe option duplication. |
| src/MongoDB.Driver/Search/SearchOptions.cs | Add Clone() and clone nested option objects. |
| src/MongoDB.Driver/Search/SearchHighlightOptions.cs | Add Clone() for highlight options. |
| src/MongoDB.Driver/Search/SearchDefinitionBuilder.cs | Add HasAncestor / HasRoot builder methods. |
| src/MongoDB.Driver/Search/SearchDefinition.cs | Extend operator type enum with HasAncestor / HasRoot. |
| src/MongoDB.Driver/Search/SearchCountOptions.cs | Add Clone() for count options. |
| src/MongoDB.Driver/Search/OperatorSearchDefinitions.cs | Implement HasAncestorSearchDefinition / HasRootSearchDefinition rendering (incl. prefix reset behavior). |
| src/MongoDB.Driver/PipelineStageDefinitionBuilder.cs | Add $search / $searchMeta overloads with returnScope and option cloning/forced stored source. |
| src/MongoDB.Driver/PipelineDefinitionBuilder.cs | Add pipeline extension overloads for returnScope search/searchMeta. |
| src/MongoDB.Driver/IAggregateFluent.cs | Add fluent overloads for returnScope search/searchMeta. |
| src/MongoDB.Driver/AggregateFluentBase.cs | Add virtual stubs + expression convenience overloads for returnScope. |
| src/MongoDB.Driver/AggregateFluent.cs | Implement new fluent overloads delegating to pipeline extensions. |
| Agents.md | Add repo/stack/commands/env-var guidance for agents. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
…s Search Add hasAncestor and hasRoot search operators for use within embeddedDocument queries, allowing searches to reference fields at ancestor or root document levels. Add returnScope support to $search and $searchMeta pipeline stages, enabling results to be returned from a nested embedded document scope rather than the root document. Add Clone() to SearchOptions and its nested options classes to avoid mutating caller-supplied options when returnScope is set.
sanych-sun
reviewed
Apr 8, 2026
| /// <returns> | ||
| /// The fluent aggregate interface. | ||
| /// </returns> | ||
| IAggregateFluent<TNewResult> Search<TNewResult>( |
Member
There was a problem hiding this comment.
I think we easily can avoid this breaking change by implementing it as an extensions method that uses AppendStage. We can consider moving this back to the interface as a part of v4 release.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Add hasAncestor and hasRoot search operators for use within embeddedDocument queries, allowing searches to reference fields at ancestor or root document levels. Add returnScope support to $search and $searchMeta pipeline stages, enabling results to be returned from a nested embedded document scope rather than the root document. Add Clone() to SearchOptions and its nested options classes to avoid mutating caller-supplied options when returnScope is set.