title: MongoDB: Find items where two specified key values are equal
body: <p>I have a mongoDB collection and an item in the collection looks like below:</p>
  
  <pre><code>{
  "_id": "52f535b56268a019bd11cc2a",
  "description": "Some description",
  "entry_date": "2014-02-07T19:36:21.430Z",
  "last_update": "2014-02-07T19:36:21.430Z",
  "r": "samestring",
  "s": "samestring"
  }
  </code></pre>
  
  <p>Dates are ISODate objects. </p>
  
  <p>This query returns items correctly </p>
  
  <pre><code>db.myCollection.find({$where : "this.entry_date &lt; this.last_update"});
  </code></pre>
  
  <p>Below query returns nothing (I expect that it returns the above item): </p>
  
  <pre><code>db.myCollection.find({$where : "this.entry_date == this.last_update"});
  </code></pre>
  
  <p>And this query returns all items (I expected again it returns the above item):</p>
  
  <pre><code> db.myCollection.find({$where :"this.r == this.s"});
  </code></pre>
  
  <p>What am I doing wrong? 
  Thanks!! </p>
  
  <p>---EDIT----</p>
  
  <p>So I tried to test with a small data like below:</p>
  
  <pre><code>&gt; db.myCollection.find({},{ _id: 0, start_date: 1, end_date: 1});
  
  { 
     "start_date" : ISODate("2014-02-07T19:36:21.430Z"),
     "end_date" : ISODate("2014-02-07T19:36:21.430Z") 
  }
  {  
     "start_date" : ISODate("2014-02-07T19:36:21.430Z"),
     "end_date" : ISODate("2014-02-07T22:39:02.114Z")
  }
  </code></pre>
  
  <p><strong>It didn't work for Date as you can see:</strong></p>
  
  <pre><code>&gt; db.myCollection.find(
      {$where: "Date(this.start_date) == Date(this.end_date)"},
      { _id: 0, start_date: 1, end_date: 1 }
    );
  
  
  
  {
      "start_date" : ISODate("2014-02-07T19:36:21.430Z"),
      "end_date" : ISODate("2014-02-07T19:36:21.430Z") 
  }
  {
      "start_date" : ISODate("2014-02-07T19:36:21.430Z"),
      "end_date" : ISODate("2014-02-07T22:39:02.114Z")
  }
  </code></pre>
  
  <p><strong>Works for string values:</strong></p>
  
  <pre><code>&gt; db.myCollection.find({$where: "this.title == this.description"},{ _id: 0, title: 1 });
  
  { "title" : "samedescription" }
  </code></pre>