title: Writing a couchdb design document
body: <p><strong>Would anyone be willing to provide a full documentation example on how to write a couchdb design document?</strong>  </p>
  
  <p>I've never been able to find a proper documentation on that. I'm able to find a list of the available methods, but not how to write them in the design document.
  For example, the <a href="http://docs.couchdb.org/en/2.1.1/ddocs/ddocs.html#view-functions" rel="noreferrer">couchdb documentation in this page</a> explains how to use a map function, but it doesn't explain that this function is implemented in the design document the following way:</p>
  
  <pre><code>{
    "views": {
      "someView": {
        "map": "function(doc){ emit(doc.name, doc) }"
      }
    }
  }
  </code></pre>
  
  <p>There are very sparse information on that in <a href="http://docs.couchdb.org/en/2.1.1/json-structure.html#design-document" rel="noreferrer">this page</a> but it seems very incomplete to me. For example it doesn't even mention there can be "validate_doc_update" in the structure.</p>
  
  <p>I think a good documentation example would be very useful in the couchdb doc itself in fact.<br>
  It could look like the following:</p>
  
  <pre><code>{
    "_id": "_design/exampleDesignDocument",
    "_rev": "1-11111111111111111111111111",
    "views": {
      "someView": {
        "map": "function(doc){ emit(doc.name, doc) }",
        ...
      }
    },
    "lists": {
      "someList": "function(head, req){ send('&lt;html&gt;hello&lt;/html&gt;') }"
    }
    ...
  }
  </code></pre>
  
  <p>This example would display usages of <strong>all design documents methods</strong> including (but not limited to if I forgot some): <strong>view (map, reduce functions...), show, list, update, filter, validate</strong>.</p>