Skip to content

Write small whole-number parameters as Int32 - #4552

Open
evanchooly wants to merge 1 commit into
audits-cutover-correctionsfrom
audits-int32-parameters
Open

evanchooly wants to merge 1 commit into
audits-cutover-correctionsfrom
audits-int32-parameters

Conversation

@evanchooly

@evanchooly evanchooly commented Nov 22, 2026 •

Copy link
Copy Markdown
Member

Stacked on #4551.

Problem

Morphia wrote several whole-number parameters as 64-bit integers where the MongoDB documentation and the shell use 32-bit ones. For example, $setWindowFields: {sortBy: {orderDate: 1}} went out as {orderDate: NumberLong(1)}, even though Sort.getOrder() is an int and the codec simply called writeInt64. The server treats the two alike, so results never differed. But the operator audits' strict serialization check caught the difference in 49 documented examples (#4548, #4549, #4550, #4551), which kept them on the legacy path. The legacy comparator ignored number types.

Changes

  • Sort directions are now written as Int32. This covers $setWindowFields, $fill, $top/$bottom/$topN/$bottomN and $sortArray, which all used writeInt64 for an int.
  • Small long parameters are written as Int32 when they fit. The new CodecHelper.whole writes Int32 when the value fits and Int64 otherwise. It covers $skip, $limit, $sample's size, $dateAdd/$dateSubtract's amount, $shift's by, $dateTrunc's binSize and the integral operands of Filters.mod. The public API still takes long, so no signatures change.
  • 48 of the 49 affected examples now convert to the case runner. The 49th, $isoWeekYear, is the server returning a Long, not an encoding issue, so it stays legacy-only. Form report: 10 overrides. Ledger: 341 cases. Legacy-only: 33.
  • The full core suite passes under both mappers (2632 tests).

Decision for review

Sort directions were written with writeInt64 although they are ints, and
skip, limit, sample size, date amounts, shift offsets, binSize and mod
operands always went out as Int64. They are now Int32 when they fit, as
the documentation and the shell write them. 48 documented examples that
failed only on this now convert to the case runner.

This branch has not been deployed

No deployments
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.

1 participant