title: Cannot use aggregation operations in $set inside updateMany
body: <p>I have a mongoDB (4.4.8) collection where I want to change the value of some field based on its previous value. For example, I want to convert all strings to uppercase.</p>
  <p>For this, I use the following query:</p>
  <pre><code>db.collection.updateMany(
      { field: { $regex: &quot;[a-z]+&quot;}},
      { $set: { field: { $toUpper: &quot;$field&quot; } } }
  )
  </code></pre>
  <p>when executing the query, it gives me the following error:</p>
  <blockquote>
  <p>MongoError: The dollar ($) prefixed field '$toUpper' in 'field.$toUpper' is not valid for storage</p>
  </blockquote>
  <p>The same occurs if I use similar operations such as <code>$concat</code> (with an array parameter) to append something to the field.</p>
  <p>When I look up similar questions, it all uses <code>update</code> and tells me to use <code>updateMany</code> instead, or it says that it only works in mongoDB &gt;= 4.2. However, I have both of these things.</p>
  <p>If I am correct, you are able to use aggregation syntax (among which <code>$toUpper</code>) in conjunction with <code>$set</code> inside updateMany queries for these newer versions of mongoDB.</p>
  <p>Does anyone know what I'm doing wrong here?</p>