Repository navigation
Generate document literals, compound group ids, $cond and $concatArrays - #4597
Open
evanchooly wants to merge 1 commit into
Open
evanchooly wants to merge 1 commit into
evanchooly wants to merge 1 commit into
Conversation
This was referenced Nov 25, 2026
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.
Stacked on #4596. Self-reviewed only.
What this solves
The generator refused every document literal ("a document literal has no binding") and every compound
$group_id("a compound _id has no binding"), and it had no binding for$condor$concatArrays. That blocked examples Morphia can write. For example,{ $group: { _id: { fiscal_year: "$fiscal_year", dept: "$dept" }, … } }in the two seeded$mergeexamples with paired reads, which #4592 couldn't generate. Another was the seven ranked-accumulator examples that setnfrom the group key with$cond.10 cases now generate (487 → 497):
$bottomN,$firstN,$lastN,$maxN,$minN,$topN);$map's$$IDX;$projectinclusion;$mergeexamples, which now run their documented read after the write.None of the committed cases are removed. Integration: 509 tests under Critter, then reflection, 0 failures. Audits suite: 445 tests, 0 failures, 4 skipped.
How
{}catalog entry bindsExpressions.document()as aFIELDSexpression, so a document of expressions isdocument().field(k, v)…. A compound_idgoes through it:group(id(document().field("y", "$year"))). So does a nested$projectdocument, which the server reads as a nested projection. Literals are emitted only where the parameter isObjectorExpression.$cond: bindscondition(if, then, else). Its{if, then, else}form becomes the array Morphia writes, under the existingCOND_ARRAYrule.$concatArrays: bindsconcatArrays(Object, Object...).Gaps, each mirroring what Morphia or Java does
DocumentExpressionCodecomits;ArrayLiteralCodecthrows on;ArrayLiteralCodeccan't write there (BsonInvalidOperationException).$condoperand (conditionbuilds aList.of);$concatArraysgiven one bare argument in its accumulator form (concatArraysalways writes an array).$projectmixing exclusions with inclusions or values, whichProjection.validateProjectionsrejects;$reduce's "Computing a Single Reduction" seedsarrayconcatelsewhere on its page, so both runs returned nothing.Decisions for review
document().field(…), fails to encode, while the same array works elsewhere. I've only made it a gap here. It may deserve a core issue.$condand$concatArrayschecks name the operator inCaseGenerator, as the earlier$textand$modones do. A general rule would wrongly reject the 20 existing accumulator cases (such assum("$runtime")) that Morphia writes bare.$regexFindAll's "Use Captured Groupings to Parse User Name" prints the$addFieldsoutput from before the pipeline's$set, like the email examples in Generate query regex, $type, $text, $expr, $mod and regex expression cases #4595.Review
Codex ran three local rounds, finding four, two and one issues. Every one is now a gap with a regression case in
GeneratorTest. The design doc and the progress log are updated.