couchdb-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Chris Anderson <>
Subject Re: validate_doc_update modifying doc?
Date Wed, 29 Apr 2009 09:14:51 GMT
On Tue, Apr 28, 2009 at 10:26 PM, Brian Candler <> wrote:
> There doesn't seem to be much documentation on validate_doc_update.
> I'm assuming that it's not possible for this function to modify the document
> it has been passed. Is that true? I was looking for somewhere for a 'model'
> to perform some basic data cleaning, e.g.
> 1. trimming superfluous spaces
> 2. converting string values to number or boolean
> 3. adding 'updated_by', 'updated_at' values
> 4. adding IP address of updater, if the HTTP request object were available
> But I guess that if validate_doc_update were able to do that, it would risk
> breaking replication.

You are correct.

However, I think we should add an _update handler which allows JavaScript
to transform arbitrary input into JSON before saving. This should open up
the range of possibility a bit without JS needing the ability to make
HTTP calls.

For instance, we can accept XML posts (or HTML form posts) and convert
them into CouchDB documents. It'd also be good for timestamps and the
other things you mention.

The crucial difference from a validation function is that it is not
run on replication, and requires hitting a design doc resource path
with the POST or PUT request (instead of a docid).

It's just a matter of writing the code. Should be an easy patch for a newcomer.


Chris Anderson

View raw message