Skip to content

PHPLIB-1761 Add builder support for $top, $bottom, $topN, $bottomN expression operators - #1910

Merged
alcaeus merged 1 commit into
mongodb:v2.xfrom
GromNaN:PHPLIB-1761
May 28, 2026
Merged

alcaeus merged 1 commit into
mongodb:v2.xfrom
GromNaN:PHPLIB-1761

Conversation

@GromNaN

@GromNaN GromNaN commented May 27, 2026 •

Copy link
Copy Markdown
Member

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Adds builder support for the $top, $bottom, $topN, and $bottomN aggregation expression operators (MongoDB 7.0+), complementing the existing accumulator variants. The generated classes implement ResolvesToAny/ResolvesToArray, are registered on the Expression facade via FactoryTrait, and include example pipeline tests.

Changes:

  • New operator classes BottomOperator, BottomNOperator, TopOperator, TopNOperator with sortBy/output/input (and n) properties and string/list validation for $input and $n.
  • Factory methods bottom(), bottomN(), top(), topN() added to Expression\FactoryTrait.
  • Example pipeline tests and corresponding canonical JSON cases in Pipelines enum.

Reviewed changes

Copilot reviewed 11 out of 11 changed files in this pull request and generated no comments.

Show a summary per file
File Description
src/Builder/Expression/BottomOperator.php Generated $bottom expression operator class.
src/Builder/Expression/BottomNOperator.php Generated $bottomN expression operator class with n validation.
src/Builder/Expression/TopOperator.php Generated $top expression operator class.
src/Builder/Expression/TopNOperator.php Generated $topN expression operator class with n validation.
src/Builder/Expression/FactoryTrait.php Factory methods exposing the four operators on Expression.
tests/Builder/Expression/BottomOperatorTest.php Pipeline example test for $bottom.
tests/Builder/Expression/BottomNOperatorTest.php Pipeline example test for $bottomN.
tests/Builder/Expression/TopOperatorTest.php Pipeline example test for $top.
tests/Builder/Expression/TopNOperatorTest.php Pipeline example test for $topN.
tests/Builder/Expression/Pipelines.php Expected canonical extended JSON for the four new examples.

@GromNaN
GromNaN requested review from alcaeus and removed request for paulinevos May 27, 2026 14:18
@codecov-commenter

codecov-commenter commented May 28, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 78.26087% with 10 lines in your changes missing coverage. Please review.
✅ Project coverage is 87.64%. Comparing base (90dca97) to head (298dbff).
⚠️ Report is 1 commits behind head on v2.x.
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
src/Builder/Expression/BottomNOperator.php 72.72% 3 Missing ⚠️
src/Builder/Expression/TopNOperator.php 72.72% 3 Missing ⚠️
src/Builder/Expression/BottomOperator.php 75.00% 2 Missing ⚠️
src/Builder/Expression/TopOperator.php 75.00% 2 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##               v2.x    #1910      +/-   ##
============================================
- Coverage     87.70%   87.64%   -0.07%     
- Complexity     3366     3394      +28     
============================================
  Files           458      462       +4     
  Lines          6720     6766      +46     
============================================
+ Hits           5894     5930      +36     
- Misses          826      836      +10     
Flag Coverage Δ
6.0-replica_set 86.50% <78.26%> (-0.06%) ⬇️
6.0-server 82.61% <78.26%> (-0.03%) ⬇️
6.0-sharded_cluster 86.29% <78.26%> (-0.06%) ⬇️
8.0-replica_set 87.51% <78.26%> (-0.07%) ⬇️
8.0-server 83.34% <78.26%> (-0.04%) ⬇️
8.0-sharded_cluster 87.34% <78.26%> (-0.07%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@alcaeus
alcaeus merged commit 9f325f8 into mongodb:v2.x May 28, 2026
17 checks passed
GromNaN added a commit to GromNaN/mongo-php-library that referenced this pull request Jul 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants