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

      1. mongodb_replace.patch
        3 kB
        Jessie Hernandez

        Issue Links

          Activity

          Hide
          kgorman Kenny Gorman added a comment -

          What version does that patch get folded into?

          Show
          kgorman Kenny Gorman added a comment - What version does that patch get folded into?
          Hide
          hhahn@adobe.com Heiko Hahn added a comment - - edited

          Will the replacement work only on whole strings, or on sub-strings as well?

          a) only replace "foo1" with "bar", but "foo1b" would stay untouched
          b) "foo1b" would be changed to "barb"

          Show
          hhahn@adobe.com Heiko Hahn added a comment - - edited Will the replacement work only on whole strings, or on sub-strings as well? a) only replace "foo1" with "bar", but "foo1b" would stay untouched b) "foo1b" would be changed to "barb"

            People

            • Votes:
              21 Vote for this issue
              Watchers:
              24 Start watching this issue

              Dates

              • Created:
                Updated: