PHPLIB-1818: Support regex in $replaceOne find argument#1925
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR extends the aggregation expression builder to allow $replaceOne’s find argument to resolve to a regex (matching $replaceAll’s existing behavior), and adds a regression test + expected pipeline fixture for the regex example.
Changes:
- Widened
$replaceOnefindtyping to acceptMongoDB\BSON\Regex/ResolvesToRegex. - Added a
$replaceOne“replace using regex” pipeline fixture and corresponding unit test.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| tests/Builder/Expression/ReplaceOneOperatorTest.php | Adds a new test covering Expression::replaceOne() with a Regex find value. |
| tests/Builder/Expression/Pipelines.php | Adds expected JSON for the $replaceOne “Replace Using Regex” example. |
| src/Builder/Expression/ReplaceOneOperator.php | Updates the operator’s find union type to accept regex inputs. |
| src/Builder/Expression/FactoryTrait.php | Updates the Expression::replaceOne() factory signature to accept regex inputs. |
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
paulinevos
approved these changes
Jun 16, 2026
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.
resolvesToRegexto thefindargument of$replaceOne, mirroring the existing support in$replaceAllJira: https://jira.mongodb.org/browse/PHPLIB-1818