-
Type: New Feature
-
Resolution: Won't Do
-
Priority: Major - P3
-
None
-
Affects Version/s: 1.3.5
-
Component/s: Write Ops
-
None
-
Query
-
(copied to CRM)
MongoDB is missing a $replace operator to perform search/replace operations on strings. MongoDB cannot currently perform the equivalent of the below SQL statement without updating each item individually:
UPDATE table SET column1 = REPLACE(column1, 'search', 'replace');
The modifier operator I propose would look like this:
db.coll.update(
{a: 1}, {$replace: {myprop: ["foo", "bar"]}});
The above statement would find all of the documents whose "a" property is 1, and replace "foo" with "bar" in the "myprop" property of said documents. A patch is attached that demonstrates this functionality. The operator should eventually support regular expressions and maybe even arrays, e.g.:
db.coll.update(
{a: 1}, {$replace: {myprop: [/foo\d+/, "bar"]}});
The above would replace all instances of "foo", followed by one or more digits, with the string "bar".
- is related to
-
SERVER-743 $append modifier
- Closed
- related to
-
SERVER-32314 Add $replaceOne and $replaceAll expressions
- Closed