Repository navigation
Generate query regex, $type, $text, $expr, $mod and regex expression cases - #4595
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 #4592. Self-reviewed only.
What this solves
The generator had no bindings for
$regex,$type,$text,$exprand$modin queries, or for$regexFind,$regexFindAlland$regexMatchin expressions. That made about 60 documented examples gaps. For example,db.products.find( { sku: { $regex: /^ABC/i } } )was reported as "query operator $regex has no binding", and six sample-dataset$groupexamples were blocked only by a{ $type: "double" }in their$match.32 cases now generate (445 → 477):
$regex;$text;$typeunblocked.Integration: 489 tests under Critter, then reflection, 0 failures. Audits suite: 444 tests, 0 failures, 4 skipped.
How
Regex filters. A query
FIELDbinding with options takes a regular expression, and each flag becomes an option call:/^ABC/iisregex("sku", "^ABC").caseInsensitive().{$regex: "p", $options: "o"}and{$regex: /p/, $options: "o"}become the one regular expression Morphia writes, under the existingREGEX_FORMrule.$type. A varargsFIELDbinding takes one value, or an array of two or more. A newconstantsfield maps MQL aliases to Morphia'sType, where the camel-to-snake conversion is wrong:"int"isINTEGER_32_BIT.$mod. A queryFIELDbinding with more than two parameters spreads its array over them:[d, r].Top-level operators. In a query, a
FILTERbinding of another form is a top-level operator, read as that form reads its value:$expris positional and$textis named.$textjoins the named-argument operators, and both rule ports now apply that rule to top-level query operators.Regex expressions.
RegexExpressionCodecwritesregex: /p/, options: "o", while pages writeregex: /p/oorregex: "p". The newREGEX_OPTIONSrule equates those spellings, implemented in bothFormEquivalenceand core'sFormRules, with golden vectors. It leaves a$string alone, since that's a field path the server evaluates.A generator bug fixed
When one test class called two factories with the same name (
Filters.eqandComparisonExpressions.eq), the generator imported both classes but left the calls unqualified, so the test wouldn't compile. No committed case had hit it yet;$exprwith$eqwould have. Static calls are now marked when emitted and resolved per class, and a shared name is called through its class.Cases that are gaps, with their reasons
java.util.regex: Morphia compiles query patterns with it. A pattern it rejects ((*UCP)) is a gap, and so is one that compiles only under its flags (regex(f, p)compiles it alone first). So is one whose inline modifiers Java folds into the written flags:(?i)abcwould be sent as/(?i)abc/i.$type: a number (2), a one-item array, or an aliasTypehas no constant for.$text: a flag writtenfalse, whichTextSearchFilterCodecomits.$mod: none of the manual's examples generate. Three demonstrate server errors (one, none or four elements). The others pass a double (4.5,4.99,-0), and thedoubleoverload would write a Double remainder where the page has an Int32.Longoperands are also gaps, because the codec writes small longs as Int32.$optionsor a string$regexbeside another operator, a repeated flag, a computed regex-expression pattern or options, and$exprgiven an array.Decisions for review
$type: "number":dev.morphia.query.Typehas noNUMBERconstant, so$type: "number"can't be written from Morphia. Several manual examples use it. Should aNUMBERconstant be added in core?$regex"Match Whole Words Only" leaves out_id: 103, which/\bline\b/matches.$addFieldsoutput from before the pipeline's$set.$regexFindAll"s Option" prints a match with one space where the data has five.$textfalse-flag gap and the$modLonggap mirror codec behavior. Rather than add catalog fields for one operator each, they're named directly inCaseGenerator.Review
Codex ran three local rounds. Round 1 found eight spellings that would have produced wrong or failing cases, and round 2 found four more. Each is now a gap or covered by a rule, with a regression case in
GeneratorTest. Round 3 was clean.The design docs (
operator-audits-design.md, the rule table inoperator-audits-form-migration.md, and the progress log) are updated.