You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@couchdb.apache.org by Pulkit Singhal <pu...@gmail.com> on 2012/06/07 16:25:00 UTC

How to add IP address field to documents

I would like to add an additional field to incoming documents in the
validate_doc_field method. This field should store client info like the IP
address. I hope that folks reading this thread find this to be same as
adding a created_at or last_modified timestamps. And ofcourse the minor
difference is that timestamps can be generated but for something like
client ip address, it would have to be picked-up/passed-in from somewhere.

I'm using CouchDB 1.2.0 and I'm used to the following method signature:
function (new_doc, old_doc, userCtx) {...}

But while Google~ing I have found two threads that hint at the existence of
a different validation signature:
  1.
http://grokbase.com/t/couchdb/user/094xjv2zaz/validate-doc-update-modifying-doc
  2. https://issues.apache.org/jira/browse/COUCHDB-1287

Does this new signature actually exist in 1.2.0 or not?
function (new_doc, old_doc, userCtx, http_headers) {...}

Overall are there any suggestion on how to add an IP address field to
documents on the fly?

Re: How to add IP address field to documents

Posted by Robert Newson <rn...@apache.org>.
The signature for validate_doc_update is;

(newDoc, oldDoc, userCtx, secObj)

The request is not exposed (and thus you can't find the IP of the client).

B.

On 7 June 2012 15:25, Pulkit Singhal <pu...@gmail.com> wrote:
> I would like to add an additional field to incoming documents in the
> validate_doc_field method. This field should store client info like the IP
> address. I hope that folks reading this thread find this to be same as
> adding a created_at or last_modified timestamps. And ofcourse the minor
> difference is that timestamps can be generated but for something like
> client ip address, it would have to be picked-up/passed-in from somewhere.
>
> I'm using CouchDB 1.2.0 and I'm used to the following method signature:
> function (new_doc, old_doc, userCtx) {...}
>
> But while Google~ing I have found two threads that hint at the existence of
> a different validation signature:
>  1.
> http://grokbase.com/t/couchdb/user/094xjv2zaz/validate-doc-update-modifying-doc
>  2. https://issues.apache.org/jira/browse/COUCHDB-1287
>
> Does this new signature actually exist in 1.2.0 or not?
> function (new_doc, old_doc, userCtx, http_headers) {...}
>
> Overall are there any suggestion on how to add an IP address field to
> documents on the fly?

Re: How to add IP address field to documents

Posted by Zachary Zolton <za...@gmail.com>.
Hi Pulkit,

You cannot modify documents in the validate_doc_update function--their
purpose is solely to check whether a document is valid. However you could
use an _update handler:

http://wiki.apache.org/couchdb/Document_Update_Handlers

Note the second parameter to that function is the request object, from
which you should be able to get the client's IP address.


Cheers,

Zach

On Thu, Jun 7, 2012 at 9:25 AM, Pulkit Singhal <pu...@gmail.com>wrote:

> I would like to add an additional field to incoming documents in the
> validate_doc_field method. This field should store client info like the IP
> address. I hope that folks reading this thread find this to be same as
> adding a created_at or last_modified timestamps. And ofcourse the minor
> difference is that timestamps can be generated but for something like
> client ip address, it would have to be picked-up/passed-in from somewhere.
>
> I'm using CouchDB 1.2.0 and I'm used to the following method signature:
> function (new_doc, old_doc, userCtx) {...}
>
> But while Google~ing I have found two threads that hint at the existence of
> a different validation signature:
>  1.
>
> http://grokbase.com/t/couchdb/user/094xjv2zaz/validate-doc-update-modifying-doc
>  2. https://issues.apache.org/jira/browse/COUCHDB-1287
>
> Does this new signature actually exist in 1.2.0 or not?
> function (new_doc, old_doc, userCtx, http_headers) {...}
>
> Overall are there any suggestion on how to add an IP address field to
> documents on the fly?
>