Uploaded image for project: 'Documentation'
  1. Documentation
  2. DOCS-13184

Investigate changes in SERVER-32314: Add $replaceOne expression

      Description

      Downstream Change Summary

      adds a $replaceOne expression.

      Description of Linked Ticket

      The query team has discussed and decided on the following syntax and semantics

      Name: $replaceOne

      Rejected Alternate Names: $replaceFirst, $replaceOnce, $stringReplaceOne

      It takes in three expressions that must evaluate to strings: an original string, a string to search for, and a string to insert. This evaluates to a new string with the first occurrence of `find` in `input` replaced by `replacement`. If no occurrences are found, it evaluates to the input string. Expressions in each argument are first evaluated and an error thrown if any input evaluates to a non-nullish non-string type.. Next, if any arguments are nullish, returns null.

      Because this is a searching algorithm and not a direct string comparison, this computation will not consider the operation's collation. This is consistent with other similar expressions like $indexOfCP and $regexFind. This expression is not required to throw an error on invalid UTF-8, though it must be implemented in such a way as to avoid undefined or unsafe behaviors when given invalid UTF-8 as input. This permits implementation of the expression as a byte-matching algorithm rather than a code point matching algorithm. This expression will not do unicode normalization. This means that a character like 'é' may not be considered a match if the input string represents it as one unicode character and the 'find' string represents it as two characters: a normal 'e' and a combining diacritical mark.
      Syntax:

      { $replaceOne: { input: <Expression>, find: <Expression>, replacement: <Expression> } }
      

      Original Ticket Description

      Hi Team,

      There is no method for string replacement in mongoDB(similar to "REPLACE" in Oracle or other DB)
      We need this functionality in our production environment.
      Kindly do the needful to add the function in your library.

      Thanks
      Devendra

      Scope of changes

      Impact to Other Docs

      MVP (Work and Date)

      Resources (Scope or Design Docs, Invision, etc.)

            Assignee:
            andrew.feierabend@mongodb.com Andrew Feierabend (Inactive)
            Reporter:
            backlog-server-pm Backlog - Core Eng Program Management Team
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved:
              4 years, 9 weeks, 6 days ago