title: CouchDB / Couchbase view ordered by number of keys
body: <p>I'm trying to write a view which shows me the top 10 tags used in my system. It's fairly easy to get the amount with _count in the reduce function, but that does not order the list by the numbers. Is there any way to do this?</p>
  
  <pre><code>function(doc, meta) {
    if(doc.type === 'log') {
      emit(doc.tag, 1);
    }
  }
  _count
  </code></pre>
  
  <p>As a result I'd like to have:</p>
  
  <ul>
  <li>Tag3 10</li>
  <li>Tag1  7</li>
  <li>Tag2  3</li>
  <li>...</li>
  </ul>
  
  <p>Instead of</p>
  
  <ul>
  <li>Tag1  7</li>
  <li>Tag2  3</li>
  <li>Tag3 10</li>
  </ul>
  
  <p>Most importantly, I do not want to transfer the full set to my application server and handle it there.</p>