title: mongodb get distinct records
body: <p>I am using <code>mongoDB</code> in which I have collection of following format.</p>
  
  <pre><code>{"id" : 1 , name : x  ttm : 23 , val : 5 }
  {"id" : 1 , name : x  ttm : 34 , val : 1 }
  {"id" : 1 , name : x  ttm : 24 , val : 2 }
  {"id" : 2 , name : x  ttm : 56 , val : 3 }
  {"id" : 2 , name : x  ttm : 76 , val : 3 }
  {"id" : 3 , name : x  ttm : 54 , val : 7 }
  </code></pre>
  
  <p>On that collection I have queried to get records in descending order like this:</p>
  
  <pre><code>db.foo.find({"id" : {"$in" : [1,2,3]}}).sort(ttm : -1).limit(3)
  </code></pre>
  
  <p>But it gives two records of same <code>id = 1</code> and I want records such that it gives 1 record per <code>id</code>.</p>
  
  <p>Is it possible in mongodb?</p>