couchdb-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Wordit Ltd <>
Subject Re: Allowing specific field value updates only
Date Wed, 17 Nov 2010 12:02:59 GMT
On Tue, Nov 16, 2010 at 10:01 PM, Jan Lehnardt <> wrote:
>  function(newDoc, oldDoc, userCtX) {
>    if(userCtx.roles.indexOf("_admin") == -1) { // not an admin
>      if(newDoc.field > oldDoc.field) { // your condition is this
>        throw({forbidden : message});
> ...

Many Thanks. Aha! So this is what oldDoc is good for :-)
I'm new to CouchDB and could not find a reason to specify oldDoc.

I couldn't figure out how to pass the new value, being in a variable,
to the validation function. From this example I see that CouchDB has
both old and new fields internally which can be accessed via oldDoc
and newDoc. It seems obvious now, but although I've read the docs and
book chapters on the subject it was not clear what was happening.

Some examples in the CouchDB book and docs, like this using oldDoc and
newDoc fields would be helpful to newbies.


View raw message