title: Mongoose Date Filter
body: <p>I have data stored in a MongoDB database and I'm using Mongoose to query the data. I'm trying to run date queries against my data to return objects from the database that fall within the specified data-range.</p>
  
  <p>My webform sends an API request to an external micro-service/api that is responsible for querying the data in the Mongo database. The API receives a single value that is representative of a number of days. eg: <code>date: "7d"</code>. I then proceed to build the mongoose query like so:</p>
  
  <pre><code>if (data.date) {
      const date = new Date();
      const dateRange = data.date.slice(0, -1); // strip the "d" from "7d"
      date.setDate(date.getDate() - dateRange);
      query.start = { $lte: date.toISOString() };
      console.log(query);
  }
  </code></pre>
  
  <p>and an example date from my database is:</p>
  
  <p><code>start: 2016-02-10T09:09:01.000Z</code></p>
  
  <p>The query is then executed:</p>
  
  <pre><code>Call.find(query, function (error, docs) {
      if (error) {
          callback(error, null);
      } else {
          callback(null, docs);
      }
  });
  </code></pre>
  
  <p>and finally, an example of <code>query</code>:</p>
  
  <pre><code>{ approved: 1, start: { '$lte': '2016-02-09T14:24:29.115Z' } }
  </code></pre>
  
  <p>However, no matter what date I send to my API the response is always empty...</p>