Add $replace Modifier Operation

XMLWordPrintableJSON

    • Type: New Feature
    • Resolution: Won't Do
    • Priority: Major - P3
    • None
    • Affects Version/s: 1.3.5
    • Component/s: Write Ops
    • None
    • Query
    • None
    • 3
    • None
    • None
    • None
    • None
    • None
    • None
    • None

      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".

              Assignee:
              Backlog - Query Team (Inactive)
              Reporter:
              Jessie Hernandez
              Votes:
              27 Vote for this issue
              Watchers:
              31 Start watching this issue

                Created:
                Updated:
                Resolved: