title: How can I search in MongoDB ISODate field from Python?
body: <p>I have an API from which I receive a query. This API is in Python.</p>
  
  <p>I call it from a django app (views.py). Then, I want to query my MongoDB collection, using mongoengine:</p>
  
  <pre><code>api_response = requests.get("http://*******", {'query':query}) #We call the API
  json_resp = api_response.json()
  person = Person.objects(__raw__=json_resp).to_json() #We search for the json_query in the DB (raw) and the output is JSON
  </code></pre>
  
  <p>It works fine but I have a problem with dates... Indeed, my Person model is as follow:</p>
  
  <pre><code>class Person(DynamicDocument):
  
      # Meta Variables
      meta = {
          'collection':'personsExample'
          }
  
      #Document variables
      PersonID = models.CharField(max_length = 6)
      FirstName = models.CharField(max_length = 50)
      LastName = models.CharField(max_length = 50)
      Gender = models.CharField(max_length = 6) #male/female
      BirthDate = models.DateField()
      CitizenCountryCode = models.CharField(max_length = 2)
  </code></pre>
  
  <p>My personsExample collection was imported via mongoimport from a CSV file:</p>
  
  <pre><code>mongoimport --host localhost --db persons --collection personsExample --type csv --file reducedPersonsExtract.csv --headerline
  </code></pre>
  
  <p>As the birth dates were set as string, I have converted them using:</p>
  
  <pre><code>db.personsExample.find().forEach(function(el){el.BirthDate = new ISODate(el.BirthDate); db.personsExample.save(el)})
  </code></pre>
  
  <p>The problem I have now is that it gives BirthDate field as follow:</p>
  
  <pre><code>"BirthDate" : ISODate("1970-12-21T00:00:00Z")
  </code></pre>
  
  <p>But in my json query, date is stored as </p>
  
  <pre><code>datetime.datetime(1970,12,21,0,0,0).isoformat()
  </code></pre>
  
  <p>Which gives:</p>
  
  <pre><code>{
      "BirthDate": "1970-12-21T00:00:00"
  }
  </code></pre>
  
  <p>Thus, the query doesn't work, I would need to make my query with </p>
  
  <pre><code>{
      "BirthDate": ISODate"1970-12-21T00:00:00Z"
  }
  </code></pre>
  
  <p>(But I can't create such objects (ISODate) with Python... )
  Or to find another way to store the date in MongoDB.</p>
  
  <p>Would you happen to know how I could solve my problem please?</p>