couchdb-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Zachary Zolton <>
Subject Re: Update handler doc ids
Date Thu, 11 Nov 2010 22:45:28 GMT
I didn't realize that the docs you were trying to update represent a
user! Yes, by all means, use their username in the doc ID. Then you
wont need to do a query just to determine the ID.

If you're considering having other types of docs in the same DB,
however, you'll probably wanna namespace the user doc IDs. For
example, user "foobar" has a doc such as "user:foobar".


On Thu, Nov 11, 2010 at 2:00 PM, Wordit Ltd <> wrote:
> Zach,
> Thanks for the confirmation on the doc ID. I need to update a doc
> belonging to the logged in user. If I use a field like "owner":
> "username" then I would need to find the doc ID first. Don't you lose
> the advantage of an update handler by first doing a read request?
> I mean you might as well do a standard read then a write. Two calls.
> Update handlers have the advantage of a single db call, or not?
> To use an update handler, I need the ID. I figured that if I set the
> doc ID to be the username, which is unique, then I can send the
> username as the doc ID to the update handler. Is there anything wrong
> with that approach?
> Marcus
> On Thu, Nov 11, 2010 at 8:45 PM, Zachary Zolton
> <> wrote:
>> Update handlers can't query the database nor access external
>> resources. They just update or create a single document based on the
>> HTTP request (and the current document object, in the case of updating
>> an existing document).
>> Moreover, if you want to update a document, you'll need to provide the
>> ID. So, you can either construct the ID from variables available at
>> that point in your program, or make a query to find the doc ID before
>> calling your update handler.
>> Give this a read:
>> If you provide more background about your scenario, I can give you
>> more explicit advice.
>> Cheers,
>> Zach
>> On Thu, Nov 11, 2010 at 8:59 AM, Wordit Ltd <> wrote:
>>> Do update handlers require the doc id, or is it possible to search for
>>> the doc as with views?
>>> I need to update the document belonging to the logged in user. (I'll
>>> use a validation function to check that.)
>>> The only workaround I could think of is using the username as the doc
>>> id. Then I call the update handler with .../handler/username?param=x
>>> Marcus

View raw message