title: Mongoose, Function Cannot Be Performed on Undefined, From Query Function
body: <p>I am trying to use today's date as the field on which to 
  search - at this juncture, without having to worry about integrating the <em>moment.js</em> library. There will be only one record with today's date in the "table". </p>
  
  <pre><code>app.dashboardreport
      .findOne()
      .$where(function() {
          return this.createdOn.toJSON().slice(0, 10) == Date.now().toJOSN().slice(0, 10);
      })
      .exec(function(err, foundDashboardReport) {
  </code></pre>
  
  <p>The <code>$where</code> function is throwing an error.</p>
  
  <blockquote>
    <p>MongoError: TypeError: Cannot call method 'toJSON' of undefined
        at _funcs1 (_funcs1:2:26) near 'createdOn.toJSON().slice(0, 10) == Date.n'  (line 2)</p>
  </blockquote>
  
  <p>It appears that "this" may not be defined; however, I know there is a record which meets those criteria. </p>
  
  <p>Am I structuring the query incorrectly? If so, what needs to change in the function so that I can filter on that condition?</p>