title: How to use fields in query evaluated criteria expressions in Mongodb?
body: <p>In Mongodb, I have a tasks collection, which has following fields, along with 25 other fields</p>
  
  <pre><code>1. timeToLive - holds the number of minutes
  2. createdDate - holds the ISODate 
  </code></pre>
  
  <p>I need to write a query, which will return me only unexpired tasks. I am trying something like following:</p>
  
  <pre><code>db.tasks.find({"timeToLive":{$gt:((new Date().getTime()-createdDate)/60000)}},{_id:1, createdDate:1, timeToLive:1}) 
  </code></pre>
  
  <p>The problem is that mongo does not recognize createdDate in $gt expression as a field from the document. I get following error:</p>
  
  <pre><code>2015-05-16T16:47:03.573-0400 E QUERY ReferenceError: createdDate is not defined at (shell):2:48
  </code></pre>
  
  <p>How do i write the field name there so that it is treated as field not a variable? I tried putting the field name in double quotes but then it is treated as a string literal.</p>
  
  <p>Any help is appreciated.</p>