title: mongodb find by comparing field values
body: <p>Is it possible to express the following SQL query in mongodb:</p>
  
  <pre><code>SELECT * FROM table AS t WHERE t.field1 &gt; t.filed2;
  </code></pre>
  
  <p><strong>edit:</strong>
  To summarize:.</p>
  
  <ol>
  <li>using a third field storing "field1 - field2" is almost perfect, but requires a little extra maintenance.</li>
  <li>$where will load and eval in JavaScript and won't use any indexes. No good for large data.</li>
  <li>map/reduce has the same problem and will go trough all records even if we need only one</li>
  </ol>