title: What is the CouchDB equivalent of the SQL COUNT(*) aggregate function?
body: <p>Yep, I'm a SQL jockey (sorta) coming into the CouchDb Map/Reduce world. I thought I had figured out how the equivalent of the COUNT(*) SQL aggregator function for CouchDB datasets with the following:</p>
  
  <p>Map:</p>
  
  <pre><code>function(doc) {
    emit(doc.name, doc);
  }
  </code></pre>
  
  <p>Reduce: </p>
  
  <pre><code>function(keys, values, rereduce){
    return values.length;
  }
  </code></pre>
  
  <p>Which I thought worked, returning something like:</p>
  
  <pre><code>"super fun C"   2
  "super fun D"   2
  "super fun E"   2
  "super fun F"   18
  </code></pre>
  
  <p>... but not really. When I add a record, this count varies wildly. Sometimes the count actually <em>decreases</em>, which was very surprising. Am I doing something wrong? Maybe I don't fully understand the concept of eventual consistency?</p>