Repository navigation
Encode a ranked accumulator's sortBy as one document - #4571
Open
evanchooly wants to merge 1 commit into
Open
evanchooly wants to merge 1 commit into
evanchooly wants to merge 1 commit into
Conversation
$top, $bottom, $topN and $bottomN with more than one sort key wrote sortBy as an array of one-key documents, which the server rejects; it takes one document whose keys are in priority order.
This was referenced Nov 23, 2026
evanchooly
added a commit
that referenced
this pull request
Nov 23, 2026
Backport of #4571 to 2.5.x. ## Problem `$top`, `$bottom`, `$topN` and `$bottomN` with more than one sort key encoded `sortBy` as an array of one-key documents, `[{score: -1}, {player: 1}]`. The server takes one document whose keys are in priority order, `{score: -1, player: 1}`, and rejects the array. A single sort key worked. ## Change `RankedResultsExpression` and `NRankedResultsExpression` always write `sortBy` as one document. The sort orders stay Int64, as 2.5 writes them; the Int32 change is 3.0 only. ## Verification - New `TestRankedSortBy`: `topN` and `bottom` with two keys encode one ordered document, and the server accepts the pipeline and breaks a tie on the second key. It fails without the fix. - `TestTopN`, `TestBottomN`, `TestFirstN` and `TestLastN` still pass.
This branch has not been deployed
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.
Found by the operator-audit generator, while generating the
$topNand$bottomNdocumented examples (next PR in the stack). Stacked on #4570.Problem
$top,$bottom,$topNand$bottomNwith more than one sort key encodedsortByas an array of one-key documents:The server takes one document whose keys are in priority order, and rejects the array:
Only a single sort key worked, which is why the existing fixtures (all single-key) never caught it. The manual's "Find the Three Highest-Rated Movies in a Single Genre"
$topNexample uses two keys.Change
RankedResultsExpressionCodecandNRankedResultsExpressionCodecalways writesortByas one document, with the keys in the order given.Verification
TestRankedSortBy:topNandbottomwith two keys encode one ordered document, and the server accepts the pipeline and breaks a tie on the second key. It fails on the old codecs:expected <{score=-1, player=1}> but was <[{score=-1}, {player=1}]>.TestTop,TestTopN,TestBottomandTestBottomNstill pass under Critter, then reflection.No docs change: the API is unchanged.
Self-reviewed only: the independent reviewers are out of quota until 2026-11-26.