title: How to convert and over write MongoDB date string into ISODate using Python PyMongo?
body: <p>I'm trying to convert a number of document strings in the format "YYYY-MM-DD" into ISODates in MongoDB and have successfully written this for the console which has the desired effect:</p>
  
  <pre><code>db.address.find({ "date" : { $type : 2 } } ).forEach(function(element){  element.date = ISODate(element.date); db.address.save(element);})
  </code></pre>
  
  <p>I'm trying to do the same in Python something like this:</p>
  
  <pre><code>client = MongoClient(my_mongodb_ip)
  db = client.address
  result = db.address.find( { "date" : { "$type" : 2 } } );
  for r in result:
      print(r['date'])
      r["date"] = datetime.strptime(r["date"], "%Y-%m-%d")
      print(r['date'])
      db.address.update_one({"company": r['company']},
           {"$set": {"date" : r['date']}})
  </code></pre>
  
  <p>Which I'd like to deliver this:</p>
  
  <pre><code>"date": {
    "$date": "2017-06-28T00:00:00.000Z"
  },
  </code></pre>
  
  <p>I don't get any updates to the DB.</p>