title: (Python) Query by dates that are stored as strings in mongoDB collection
body: <p><strong>How can you query the db.collection by dates when the dates are stored as strings?</strong> Since this database is large and growing, a for loop to convert each datetime does not make sense for a long term solution. </p>
  
  <p>I am creating a pipeline to query a collection for any given dates, but every query I try results in an empty list [].</p>
  
  <p><strong><em>date format:</em></strong> <strong>"ts": "2018-09-26T21:02:19+00:00"</strong></p>
  
  <p>I am looking for a solution that avoids reformmating the datetime key in a for loop because the database is growing, and it would take longer than running a non datetime query, converting to pandas then converting to datetime later downstream in the script. </p>
  
  <p>I've tried several attempts from various SO posts and they produce empty results:
  1. </p>
  
  <pre><code>n = db.collection.find({'ts':{'$lt':datetime.now(), '$gt':datetime.now() - timedelta(hours=10000)}})
  
  print(n)
  []
  </code></pre>
  
  <p>2.:</p>
  
  <pre><code>start = datetime(2019, 2, 2, 6, 35, 6, 764)
  end = datetime(2019, 2, 20, 6, 55, 3, 381)
  
  doc = db.collection.find({'ts': {'$gte': start, '$lt': end}})
  print(doc)
  []
  </code></pre>
  
  <p>However I am beginning to think it is how my date is formatted in the ts key. Here is an example of a document:</p>
  
  <pre><code>{
  "_id": {
      "$oid": "5babf3dab512dd0165efd36c"
  },
  "d": [
      {
          "d": [
              17317,
              16556,
              9680,
              55982,
              45948
          ],
          "h": 74.65,
          "ts": "2018-09-26T21:02:19+00:00",
          "p": [
              61,
              76,
              137,
              152,
              122
          ],
          "si": "9829563c95d0155f",
          "t": 24.82,
          "ti": "0000000000000000"
      },
      {
          "d": [
              17821,
              17488,
              9199,
              56447,
              44089
          ],
          "h": 80.09,
          "ts": "2018-09-26T21:02:19+00:00",
          "p": [
              61,
              76,
              137,
              152,
              122
          ],
          "si": "a42fbc88a44a316f",
          "t": 25.1,
          "ti": "0000000000000000"
      }
  ],
  "gi": "GW-P1007"}
  </code></pre>
  
  <p>Am i missing something here? Is this a formatting problem?</p>