title: How can I update all documents in a collection to create a new field that replaces certain characters in an existing field?
body: <p>I want to add a new field called <code>searchname</code> to all documents based on the currently existing <code>name</code> but taking the string inside name and replacing all é with regular e. How can I do this in either the shell or a driver. I'm trying this in pymongo but I'm getting the error ```Invalid $set :: caused by :: An object representing an expression must have exactly one field``</p>
  <p>Here is the code I'm trying to run</p>
  <pre><code>test_collection.update_many({},
      [{
          &quot;$set&quot;: {
              &quot;searchName&quot;: {
                  &quot;$reduce&quot;: {
                      &quot;input&quot;: [
                          [&quot;é&quot;, &quot;e&quot;],
                          [&quot;à&quot;, &quot;a&quot;],
                          [&quot;í&quot;, &quot;i&quot;],
                          [&quot;ó&quot;, &quot;o&quot;],
                          [&quot;ú&quot;, &quot;u&quot;],
                          [&quot;ñ&quot;, &quot;n&quot;],
                      ],
                      &quot;initialValue&quot;: {
                          &quot;$toLower&quot;: &quot;$name&quot;
                      },
                      &quot;in&quot;: {
                          &quot;$replaceAll&quot;: {
                              &quot;input&quot;: &quot;$$value&quot;,
                              &quot;find&quot;: {
                                  &quot;$arrayElemAt&quot;: [
                                      &quot;$$this&quot;,
                                      0
                                  ]
                              }
                          },
                          &quot;replacement&quot;: {
                              &quot;$arrayElemAt&quot;: [
                                  &quot;$$this&quot;,
                                  1
                              ]
                          }
          }}}}}])
  </code></pre>