From 255bd5f38f9b34c6e90ea018a5b209f5dcf23e8e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Tamarelle?= Date: Mon, 15 Jun 2026 11:32:27 +0200 Subject: [PATCH 1/2] Support regex in $replaceOne find argument --- definitions/expression/replaceOne.yaml | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/definitions/expression/replaceOne.yaml b/definitions/expression/replaceOne.yaml index 7934d50a..f9761d2b 100644 --- a/definitions/expression/replaceOne.yaml +++ b/definitions/expression/replaceOne.yaml @@ -18,6 +18,7 @@ arguments: type: - resolvesToString - resolvesToNull + - resolvesToRegex description: | The string to search for within the given input. Can be any valid expression that resolves to a string or a null. If find refers to a field that is missing, $replaceAll returns null. - name: replacement @@ -44,3 +45,20 @@ tests: item: types: - bsonType: String + - name: Replace Using Regex + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/replaceOne/#replace-using-regex + pipeline: + - $project: + item: + $replaceOne: + input: $item + find: !bson_regex '\bblue paint\b' + replacement: red paint + schema: + inventory: + _id: + types: + - bsonType: Number + item: + types: + - bsonType: String From 4aacd0ec2d15491cbd5ca2c7575747cfa28b6dfd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Tamarelle?= Date: Mon, 15 Jun 2026 13:12:21 +0200 Subject: [PATCH 2/2] Fix descriptions referencing \$replaceAll instead of \$replaceOne --- definitions/expression/replaceOne.yaml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/definitions/expression/replaceOne.yaml b/definitions/expression/replaceOne.yaml index f9761d2b..458d31ce 100644 --- a/definitions/expression/replaceOne.yaml +++ b/definitions/expression/replaceOne.yaml @@ -13,20 +13,20 @@ arguments: - resolvesToString - resolvesToNull description: | - The string on which you wish to apply the find. Can be any valid expression that resolves to a string or a null. If input refers to a field that is missing, $replaceAll returns null. + The string on which you wish to apply the find. Can be any valid expression that resolves to a string or a null. If input refers to a field that is missing, $replaceOne returns null. - name: find type: - resolvesToString - resolvesToNull - resolvesToRegex description: | - The string to search for within the given input. Can be any valid expression that resolves to a string or a null. If find refers to a field that is missing, $replaceAll returns null. + The string or regex to search for within the given input. Can be any valid expression that resolves to a string, a regex, or a null. If find refers to a field that is missing, $replaceOne returns null. - name: replacement type: - resolvesToString - resolvesToNull description: | - The string to use to replace all matched instances of find in input. Can be any valid expression that resolves to a string or a null. + The string to use to replace the first matched instance of find in input. Can be any valid expression that resolves to a string or a null. tests: - name: Example link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/replaceOne/#example