Skip to content

Instantly share code, notes, and snippets.

@sebastianrothbucher
Created September 19, 2014 20:43
Show Gist options
  • Save sebastianrothbucher/23ed63bb4b8d5e95eb42 to your computer and use it in GitHub Desktop.
Save sebastianrothbucher/23ed63bb4b8d5e95eb42 to your computer and use it in GitHub Desktop.
Config values in Couch Design Docs

Take the following simple CouchDB named test:

{"total_rows":2,"offset":0,"rows":[
{"id":"_design/tst","key":"_design/tst","value":{"rev":"3-312aaf2d14174ef415d185d460f4380a"},"doc":{"_id":"_design/tst","_rev":"3-312aaf2d14174ef415d185d460f4380a","shows":{"own":"function(doc, req){return this.configval+\" - \"+doc.docval;}"},"configval":"bla"}},
{"id":"tst2","key":"tst2","value":{"rev":"2-2f1a6af53d8b871b677f79da8e0a2f45"},"doc":{"_id":"tst2","_rev":"2-2f1a6af53d8b871b677f79da8e0a2f45","docval":"blup"}}
]}

It consists of two docs: one tst2 (a normal doc with a value "docval") plus a design document "_design/tst" with a config value "configval" and a show function printing both config val and doc val.

Lesson learned: this in a design doc references to the design doc itself and provides some convenient way of storing config / specialization / customization there. Try by calling http://localhost:5984/test/_design/tst/_show/own/tst2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment