couchdb-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From eric casteleijn <>
Subject Re: sample couchdb application
Date Fri, 08 Jan 2010 13:55:10 GMT
On 01/08/2010 07:46 AM, Matteo Caprari wrote:
> Hello again.
> Two questions.
> 1. Why the _update functions can't accept POST? That would make it
> possible to send documents
> using just plain html forms, provided that the function can then
> decody the request body.
> 2. I'm about to add support for voting questions. A vote is a number
> that a user can bump up or push down.
> It can be done by
>     (A) adding one document for each vote
>     (B) having a 'votes' property on each question document
>     (C) one 'votes' document for each question document
> I'd pick B and have the client send votes to an _update handler,
> always updating the latest revision in the database, regardless of the
> document revision
> a user is voting on.
> The only problem with that is conflict resolution in case of document body edit:
> - User starts editing a question body.
> - In the meantime other users vote the question up and down, causing
> the rev number to change.
> - User submits his changes and is alerted that there is a conflict.
> Only it's not a real conflict because a different aspect of the
> document
> has been edited.
> If the client holds a copy of the original document, it could
> automatically merge the documents, or maybe have _update handler do
> that.
> Does this make any sense?

It does to me ;). We've done something very similar in desktopcouch to 
resolve conflicts we don't actually care about:

I've created an update_fields method, that takes a list of fields[*], 
their last known values, and the values we want to write. The write will 
succeed without conflict as long as the specified fields have not been 
modified in the interim, but changes to any other field will be merged 
into the end result.

In case of conflicts it can't resolve, it raises an error, with the old 
expected value and the value it found in the database, so a client can 
do conflict resolution and try again.

This is obviously something that does not work for all cases: The fields 
you update using this function must be totally independent of any other 
fields in the document, for one thing.

[*] paths to fields actually, so that you can update say a single value 
in a nested dictionary.

View raw message