Details

    • Type: New Feature
    • Status: Open
    • Priority: Major - P3
    • Resolution: Unresolved
    • Affects Version/s: 1.3.5
    • Fix Version/s: Backlog
    • Component/s: Write Ops
    • Labels:
      None

      Description

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

        Attachments

          Issue Links

            Activity

              People

              • Votes:
                22 Vote for this issue
                Watchers:
                25 Start watching this issue

                Dates

                • Created:
                  Updated: