title: Mongoose query where with missing (or undefined) fields
body: <p>I have an issue that I have a messy MongoDB database with a revised Mongoose scheme.</p>
  
  <p>I want to be able to query using the <code>where</code> command, but if the field is missing or <code>undefined</code> in any found record then Mongoose returns an error.</p>
  
  <p>For instance:</p>
  
  <pre><code>  return this.find({personID: req.user._id})
    .where('rangeBefore').lt(time);
  </code></pre>
  
  <p>This returns an error because some records do not have <code>rangeBefore</code>.</p>
  
  <p>What I want to achieve is that any record without the <code>rangeBefore</code> field is filtered out (i.e. it fails the <code>where</code> test).</p>
  
  <p>I have tried prefixing with <code>exists</code> like this:</p>
  
  <pre><code>  return this.find({personID: req.user._id})
    .exists('rangeBefore').where('rangeBefore').lt(time);
  </code></pre>
  
  <p>but I still get an error.</p>
  
  <p>Can anyone suggest a way to ignore records with <code>undefined</code> fields, rather than returning an error?  </p>