incubator-couchdb-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Dave Cottlehuber <...@jsonified.com>
Subject Re: Analytics Using validate_doc_update
Date Mon, 01 Oct 2012 13:32:55 GMT
On 1 October 2012 12:58, Vikkie Johl <vikkie.johl@gmail.com> wrote:
> Hi !,
>
> Whenever I save a new document, I want perform some analytics based on the
> previously (last) saved document. Is there any way I go do the same, I
> tried using validate_doc_update but not much help.
>
> Regards,
> Vikkie

Hey Vikkie,

I moved this to user@ as it's more appropriate. Welcome to CouchDB :-)

    function(newDoc, oldDoc, userCtx) { … stuff …}

This is the spec for a validation function[1]. So you have all the
oldDoc version available to play with**

I assume you mean last saved version of the same doc, and not the n-1
doc that was PUT.

Don't forget that:
- the oldDoc will only be available if you are providing an id either
in the URL or in the doc body
- the validation function is also run during replication
- not all versions of a document are passed during replication, only
the latest leaf docs on each branch***
[1]: http://guide.couchdb.org/draft/validation.html
[2]: http://wiki.apache.org/couchdb/Document_Update_Validation

**: caveat that you can't get to the body of attachments, you can only
read the stubs.
***: hand-wavey

Mime
View raw message