title: Querying database for all records in each hour
body: <p>I have a database which stores a snapshot of the temperature every minute. I have an API endpoint for populating an hourly historic temperature bar graph. At the moment, I create an array of hourly periods over 24 hrs as UNIX timestamps, the logic then looks like this:</p>
  
  <pre><code>db.Temperature.aggregate('value', 'AVG', {
      where: {
          createdAt: {
              $lt: start,// new Date(UnixStartTime + 3600000) end of the hour for a given start point
              $gt: end// new Date(UnixStartTime)
          },
      },
  });
  </code></pre>
  
  <p>The issue with this is that of course if I make the query at 11:30, the 11 O'clock reading is actually everything from <code>10:30 to 11:30</code>, where it should be <code>11:00 to 11:30</code> and the previous value should be <code>10:00 to 11:00</code>.</p>
  
  <p>How can I fix this logic such that the returned values are actually from the correct hour period?</p>