Skip to content

CSHARP-4901 Add support for SearchMeta facet without operator#1947

Open
kyra-rk wants to merge 3 commits intomongodb:mainfrom
kyra-rk:csharp-4901
Open

CSHARP-4901 Add support for SearchMeta facet without operator#1947
kyra-rk wants to merge 3 commits intomongodb:mainfrom
kyra-rk:csharp-4901

Conversation

@kyra-rk
Copy link
Copy Markdown
Contributor

@kyra-rk kyra-rk commented Apr 10, 2026

No description provided.

@kyra-rk kyra-rk added bug Fixes issues or unintended behavior. feature Adds new user-facing functionality. and removed bug Fixes issues or unintended behavior. labels Apr 10, 2026
@kyra-rk kyra-rk requested review from ajcvickers and papafe and removed request for ajcvickers April 13, 2026 15:12
@kyra-rk kyra-rk marked this pull request as ready for review April 15, 2026 21:11
@kyra-rk kyra-rk requested a review from a team as a code owner April 15, 2026 21:11
Copilot AI review requested due to automatic review settings April 15, 2026 21:11
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds the ability to build/render Atlas Search facet definitions without specifying an underlying search operator, enabling $searchMeta facet use cases that only bucket on facets.

Changes:

  • Added SearchDefinitionBuilder.Facet(...) overloads that accept only facets (no operator).
  • Updated facet operator rendering to omit the "operator" field when not provided.
  • Added unit/integration tests covering facet-without-operator for both typed/untyped builders and $searchMeta.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.

File Description
src/MongoDB.Driver/Search/SearchDefinitionBuilder.cs Adds Facet(IEnumerable<SearchFacet<TDocument>>) and Facet(params SearchFacet<TDocument>[]) overloads to support operator-less facet definitions.
src/MongoDB.Driver/Search/OperatorSearchDefinitions.cs Makes facet rendering conditional on whether an operator was provided (omit "operator" when null).
tests/MongoDB.Driver.Tests/Search/SearchDefinitionBuilderTests.cs Adds rendering tests for facet definitions without an operator (typed and untyped).
tests/MongoDB.Driver.Tests/Search/AtlasSearchTests.cs Adds an integration test verifying $searchMeta facet behavior without an operator.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

: base(OperatorType.Facet)
{
_operator = Ensure.IsNotNull(@operator, nameof(@operator));
_operator = @operator;
Copy link

Copilot AI Apr 15, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removing the non-null check for @operator changes behavior for the existing Facet(SearchDefinition<TDocument> @operator, ...) overloads: passing null previously threw ArgumentNullException, but now it silently renders a facet without an operator. To avoid masking bugs and preserve the prior contract, add a null check in the Facet overloads that take @operator (or restore validation in FacetSearchDefinition and introduce a separate code path/ctor for the operator-optional variant).

Suggested change
_operator = @operator;
_operator = Ensure.IsNotNull(@operator, nameof(@operator));

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, this contradicts the original purpose of the ticket, which was to to make operator optional as per the Atlas Search docs.

Comment on lines +496 to +499
subject.Facet( facetBuilder.String("string", x => x.FirstName, 100)),
expected);
AssertRendered(
subject.Facet( facetBuilder.String("string", "FirstName", 100)),
Copy link

Copilot AI Apr 15, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There’s an extra space after the opening parenthesis in subject.Facet( facetBuilder... which is inconsistent with the surrounding formatting in this test file and makes the call harder to scan. Consider removing the space for consistency.

Suggested change
subject.Facet( facetBuilder.String("string", x => x.FirstName, 100)),
expected);
AssertRendered(
subject.Facet( facetBuilder.String("string", "FirstName", 100)),
subject.Facet(facetBuilder.String("string", x => x.FirstName, 100)),
expected);
AssertRendered(
subject.Facet(facetBuilder.String("string", "FirstName", 100)),

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will adjust the formatting to be on the next line!

Comment on lines +496 to +499
subject.Facet( facetBuilder.String("string", x => x.FirstName, 100)),
expected);
AssertRendered(
subject.Facet( facetBuilder.String("string", "FirstName", 100)),
Copy link

Copilot AI Apr 15, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There’s an extra space after the opening parenthesis in subject.Facet( facetBuilder... which is inconsistent with the surrounding formatting in this test file and makes the call harder to scan. Consider removing the space for consistency.

Suggested change
subject.Facet( facetBuilder.String("string", x => x.FirstName, 100)),
expected);
AssertRendered(
subject.Facet( facetBuilder.String("string", "FirstName", 100)),
subject.Facet(facetBuilder.String("string", x => x.FirstName, 100)),
expected);
AssertRendered(
subject.Facet(facetBuilder.String("string", "FirstName", 100)),

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will adjust the formatting to be on the next line!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature Adds new user-facing functionality.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants