title: Rails & Mongoid unique results
body: <p>Consider the following example of mongo collection:</p>
  
  <pre><code>{"_id" : ObjectId("4f304818884672067f000001"), "hash" : {"call_id" : "1234"}, "something" : "AAA"}
  {"_id" : ObjectId("4f304818884672067f000002"), "hash" : {"call_id" : "1234"}, "something" : "BBB"}
  {"_id" : ObjectId("4f304818884672067f000003"), "hash" : {"call_id" : "1234"}, "something" : "CCC"}
  {"_id" : ObjectId("4f304818884672067f000004"), "hash" : {"call_id" : "5555"}, "something" : "DDD"}
  {"_id" : ObjectId("4f304818884672067f000005"), "hash" : {"call_id" : "5555"}, "something" : "CCC"}
  </code></pre>
  
  <p>I would like to query this collection and get only the first entry for each "call_id", in other words i'm trying to get unique results based on "call_id".
  I tried to use .distinct method:</p>
  
  <pre><code>@result = Myobject.all.distinct('hash.call_id')
  </code></pre>
  
  <p>but the resulting array will contain only the unique call_id fields:</p>
  
  <pre><code>["1234", "5555"]
  </code></pre>
  
  <p>and I need all the other fields too.
  Is it possible to make a query like this one?:</p>
  
  <pre><code>@result = Myobject.where('hash.call_id' =&gt; Myobject.all.distinct('hash.call_id'))
  </code></pre>
  
  <p>Thanks</p>