Design documents are one of the special things that CouchDB has in its arsenal that you might not expect from a database. On the surface, design documents look the same as regular documents. They have the standard fields: _id
and _rev
, and can be created, read, updated, and deleted. But unlike normal documents, they contain application code in the form of JavaScript and have a specific structure. This JavaScript can drive validation, display views with map
and reduce
functions, and a whole lot more. We'll touch on each of these features and how to use them shortly.
A basic design document might look similar to the following:
{ —_id— : —_design/application—, "_rev" : "3-71c0b0bd73a9c9a45ea738f1e9612798", "views" : { "example" : { "map" : "function(doc){ emit(doc._id, doc)}" } } }
The _id
and _rev
should look familiar, but unlike other documents so far, the _id
has a readable name: _design/example
. Design documents are identified as such by having...