CouchDB tips
Tips are running lists of the latest hints that helped.
Contents
Design docs and validate_doc_update
I thought that design impositions required the _design/<name>/ prefix to be run. Evidently this is not so.
Using two design documents in the same database. The first one defines validate_doc_update like this:
function (newDoc, oldDoc, userCtx) { }
All by itself, this doesn't stop anything.
Push a second design doc from a new couchapp directory that defines validate_doc_update like this:
function (newDoc, oldDoc, userCtx) {
throw({forbidden:'no way'}); }
Now the database won't accept updates to normal documents. Evidently the validation functions in all of a database's design documents are applied.
Design document logs
Use log() to capture object as JSON in /var/log/couchdb/couch.log. Here it's in a validate_doc_update definition:
function (newDoc, oldDoc, userCtx) {
log(userCtx);}
PUT, POST and _rev
Use the _rev from a GET to figure out what to POST:
curl -X GET http://localhost:5984/testxportr/xxx
curl -vX POST -d
'{"xxx":1,"_id":"xxx","_rev":"1-6e2024f0c3a3e313a47a15d8086f1817"}'
http://localhost:5984/testxportr/
You can't POST to the same URL that you GET. But you can PUT a new document directly to an _id so long as it doesn't already exist.
Couchapp and EOL
When using couchapp, use vim -b and set noeol to eliminate end-of-line characters. For example, in a language file containing the string javascript, if you edit it normally, the end-of-line character shows up in the design document after you push it using couchapp.
It's not clear whether these extra characters mess up anything besides my fragile sense of aesthetics. I was assuming that for something like language it might mess up a validation check someplace. But for a validate_doc_update it didn't seem to hurt anything. Go fish.