couchdb-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Damien Katz <>
Subject Re: Trouble with replication
Date Thu, 29 Jan 2009 18:19:33 GMT

On Jan 29, 2009, at 12:50 PM, Chris Anderson wrote:

> On Thu, Jan 29, 2009 at 1:03 AM, Brian Candler <>  
> wrote:
>> can validate_doc_update also modify the data being stored?
> No. Side effects in that function become would deeply confusing, as it
> runs during replication as well as for client-updates.


My thinking to fill in the gap is we will provide something like a  
server side stored procedure, that when given a newly updated document  
can modify it and perform complex logic on it and then save it. Then  
custom validation functions would refuse any documents that aren't  
correctly processed, but allow through correctly process replicated  

So you'd have a design doc that looks something like this

	update_article: "function(editDoc, userCtx) {var prevDoc =  
load_prev_rev(editDoc);  add_diffs(editDoc, prevDoc};  save(editDoc)}"
validate_doc_update: "function(newDoc, oldDoc, userCtx) {if ! 
validate_diffs(newDoc)) {throw {forbidden: 'Documents must be saved  
via update_article'}",

And when saving a new doc:

PUT /db/_proc/foo/update_article


View raw message