title: Mongoose.countDocuments is not working when counting documents by moment js that are created last year
body: <p>I am working on an open-source library called wertik-js and it uses Graphql, I have added reporting type helpers that return counting of mongoose models based on created at. Here in this case I have reportings like, total_count, total_added_last_year etc, total_added_today etc, For today I have filtered in this way:</p>
  
  <pre class="lang-js prettyprint-override"><code>model.countDocuments(
    {
      created_at: {
        $gt: moment().startOf("day"),
        $lt: moment().endOf("day"),
      },
    },
    function (err, count) {
      resolve(count);
    }
  );
  
  </code></pre>
  
  <p>And it works pretty fine. When using for last year, I have data created last year. Which counts in this way for last year</p>
  
  <pre class="lang-js prettyprint-override"><code>model.countDocuments(
    {
      created_at: {
        $gt: moment().subtract(1, "year").startOf("year"),
        $lt: moment().subtract(1, "year").endOf("year"),
      },
    },
    function (err, count) {
      resolve(count);
    }
  );
  </code></pre>
  
  <p>But last year count is not working and every time it returns 0 but I am sure I have written the query in right way and it returns the wrong number which is 0. Where total_added_today returns fine. </p>
  
  <p>To reproduce the bug, you can pull this branch <a href="https://github.com/Uconnect-Technologies/wertik-js/tree/188-graphql-or-rest-api-enpoint-to-show-all-stats" rel="nofollow noreferrer">https://github.com/Uconnect-Technologies/wertik-js/tree/188-graphql-or-rest-api-enpoint-to-show-all-stats</a> and:</p>
  
  <ol>
  <li>Install packages and run the server sudo yarn &amp;&amp; sudo yarn dev</li>
  <li>Go to <a href="http://localhost:4000/" rel="nofollow noreferrer">http://localhost:4000/</a></li>
  <li>And execute the graphql query:</li>
  </ol>
  
  <pre><code>{
    roleStats {
      total_count
      total_added_this_month
      total_added_this_week
      total_added_last_7_days
      total_added_today
      total_added_last_month
      total_added_last_90_days
      total_added_last_year
      total_added_this_year
    }
  }
  </code></pre>
  
  <p>And you will be able to reproduce the error. </p>
  
  <p>You can check this file <a href="https://github.com/Uconnect-Technologies/wertik-js/blob/188-graphql-or-rest-api-enpoint-to-show-all-stats/src/framework/reporting/index.ts#L110" rel="nofollow noreferrer">https://github.com/Uconnect-Technologies/wertik-js/blob/188-graphql-or-rest-api-enpoint-to-show-all-stats/src/framework/reporting/index.ts#L110</a> from line 110 mongoose starts.</p>
  
  <p>What I am doing wrong here?</p>
  
  <p>Any help will be considered as a contribution to this open-source project.</p>
  
  <p><strong>Edit</strong></p>
  
  <p>An example document I am searching:</p>
  
  <pre><code>{
      "_id": {
          "$oid": "5ed85b8893280c021c2ddfd6"
      },
      "name": "John",
      "created_at": "Thu Jun 04 2019 07:25:12 GMT+0500 (Pakistan Standard Time)",
      "updated_at": "Thu Jun 04 2019 07:25:12 GMT+0500 (Pakistan Standard Time)",
      "__v": 0
  }
  </code></pre>