On Tue, Nov 16, 2010 at 10:01 PM, Jan Lehnardt <[email protected]> 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. Marcus
