title: Getting Distinct values of multiple values in Mongodb
body: <p>Let's imagine I have the following collection of books (Edited out the ID field for compactness):</p>
  
  <pre><code>{ "author" : "Steve Jones", "title" : "Fun Stuff",    "edition" : "2010" }
  { "author" : "Steve Jones", "title" : "Fun Stuff",    "edition" : "2011" }
  { "author" : "Steve Jones", "title" : "Boring Stuff", "edition" : "2010" }
  { "author" : "Ben Johnson", "title" : "Other Stuff",  "edition" : "2010" }
  </code></pre>
  
  <p>What should I do I want to find only the latest edition of each book? In other words: I want to get a result which omits the 2010 edition of Steve Jones' <em>Fun Stuff</em>, and only has the 2011 edition:</p>
  
  <pre><code>{ "author" : "Steve Jones", "title" : "Fun Stuff",    "edition" : "2011" }
  { "author" : "Steve Jones", "title" : "Boring Stuff", "edition" : "2010" }
  { "author" : "Ben Johnson", "title" : "Other Stuff",  "edition" : "2010" }
  </code></pre>
  
  <p>If this was a relational database and I were writing a query, I'd probably write something like <code>SELECT DISTINCT title, DISTINCT author, edition WHERE 1 SORT BY edition DESC</code>. So my instinct coming from a SQL background is to look up <a href="http://docs.mongodb.org/manual/reference/method/db.collection.distinct/" rel="nofollow noreferrer">db.collection.distinct()</a> but it seems to work pretty differently than what I'm used to; it only returns an array with each distinct value for that a single field.</p>
  
  <p>Is this something that I would need to tackle programmatically? Or can I do this entirely with mongo functions and bson?</p>