Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-829

Add $replace Modifier Operation

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

      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-server-query Backlog - Query Team (Inactive)
            Reporter:
            jrhernandez Jessie Hernandez
            Votes:
            27 Vote for this issue
            Watchers:
            31 Start watching this issue

              Created:
              Updated:
              Resolved: