On 17 Nov 2010, at 22:12, Mike Fedyk wrote:
> On Wed, Nov 17, 2010 at 4:02 AM, Wordit Ltd <[email protected]> wrote:
>> 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.
>>
>
> Kinda late now, but maybe it should be called "currentDoc".
> Especially since you're possibly rejecting the newDoc, it just may not
> be old anymore. ;)
The naming is arbitrary, for all CouchDB is concerned you can write this:
function(fatherson, monkeykid, what) {
...
}
Cheers
Jan
--