title: PyMongo Transform DateField
body: <p>I am managing with pymongo to perform some queries over a Premier Leage data base.</p>
  <p><a href="https://pkgstore.datahub.io/sports-data/english-premier-league/season-1819_json/data/175e7265560b9ab9102566c5dae7cbf3/season-1819_json.json" rel="nofollow noreferrer">https://pkgstore.datahub.io/sports-data/english-premier-league/season-1819_json/data/175e7265560b9ab9102566c5dae7cbf3/season-1819_json.json</a></p>
  <p>However I have some troubles dealing with the <code>Date</code> field, which is in <code>dd/mm/yyyy</code> string format and I cannot find a way to update my collection by setting another Field in which that Date is transformed into a datetime object, which can be ordered.</p>
  <pre><code>db = client['PremierLeague']
  col = db['2018-2019']
  </code></pre>
  <p>I have tried</p>
  <pre><code>col.update_many({},{&quot;$set&quot;:{&quot;DateTime&quot;:{datetime.strptime(&quot;$Date&quot;,'%d/%m/%Y')}}},upsert = True)
  </code></pre>
  <p>getting</p>
  <pre><code>ValueError: time data '$Date' does not match format '%d/%m/%Y'
  </code></pre>
  <p>I have also tried</p>
  <pre><code>col.update_many({},{&quot;$set&quot;:{&quot;DateTime&quot;:{&quot;$dateFromString&quot;:{ &quot;date&quot;: &quot;$Date&quot;, &quot;format&quot;: '%d-%m-%Y'}} }},upsert = False)
  </code></pre>
  <p>Getting a <code>WriteError</code></p>
  <pre><code>WriteError: The dollar ($) prefixed field '$dateFromString' in 'DateTime.$dateFromString' is not valid for storage., full error: {'index': 0, 'code': 52, 'errmsg': &quot;The dollar ($) prefixed field '$dateFromString' in 'DateTime.$dateFromString' is not valid for storage.&quot;}
  </code></pre>
  <p>Thanks in advance for your interest.</p>