title: How to calculate howmany elapsed milliseconds into a range of date
body: <p>I have a problem to make a selection using new Date() and a Date attribute in a specific collection.</p>
  
  <p><strong>For example, this is a collection with a document:</strong></p>
  
  <p><code>{_id: ObjectId(12345), 'last_execution': ISODate("2016-12-12T11:35:44.832Z")}</code></p>
  
  <p>I want to fetch documents where since last_execution to now have passed 15 minutes.</p>
  
  <p><strong>I can do this using $where and functions as follow:</strong></p>
  
  <pre><code>db.collection.find( { $where: function() { return ((new Date().getTime() - this.last_execution.getTime()) &gt;= (15 * 60 * 1000) ) } } )
  </code></pre>
  
  <p>But according to MongoDB's documentation this way the indexes won't be used.</p>
  
  <p>Any ideas?</p>
  
  <p><strong>Thank you!</strong></p>