title: Sorting CouchDB result by value
body: <p>I'm brand new to CouchDB (and NoSQL in general), and am creating a simple Node.js + express + nano app to get a feel for it. It's a simple collection of books with two fields, 'title' and 'author'.</p>
  
  <p><strong>Example document:</strong></p>
  
  <pre><code>{
     "_id": "1223e03eade70ae11c9a3a20790001a9",
     "_rev": "2-2e54b7aa874059a9180ac357c2c78e99",
     "title": "The Art of War",
     "author": "Sun Tzu"
  }
  </code></pre>
  
  <p><strong>Reduce function:</strong></p>
  
  <pre><code>function(doc) {
    if (doc.title &amp;&amp; doc.author) {
      emit(doc.title, doc.author);
    }
  }
  </code></pre>
  
  <p>Since CouchDB sorts by key and supports a 'descending=true' query param, it was easy to implement a filter in the UI to toggle sort order on the title, which is the key in my results set. Here's the UI:</p>
  
  <p><a href="https://i.stack.imgur.com/Q9gaf.jpg" rel="nofollow noreferrer">List of books with link to sort title by ascending or descending</a></p>
  
  <p>But I'm at a complete loss on how to do this for the author field.</p>
  
  <p>I've seen <a href="https://stackoverflow.com/questions/2817703/sorting-couchdb-views-by-value">this question</a>, which helped a poster sort by a numeric reduce value, and I've read <a href="http://geekiriki.blogspot.com/2010/08/couchdb-using-list-functions-to-sort.html" rel="nofollow noreferrer">a blog post</a> that uses a list to also sort by a reduce value, but I've not seen any way to do this on a string value without a reduce.</p>