couchdb-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Brian Candler <>
Subject Re: Ensuring unique attributes across documents?
Date Sun, 15 Nov 2009 09:14:56 GMT
On Sun, Nov 15, 2009 at 08:15:10AM +0000, Brian Candler wrote:
> But in this case there are more relaxed solutions.

Also, if you've read the following at

  "Most applications require no special planning to take advantage of
  distributed updates and replication."

You should note that relying on doc_id to enforce uniqueness of a particular
value will prevent your application from working properly in a distributed
multi-master setup, since you'll no longer have this uniqueness guarantee.
Similarly, relying on 409 PUT responses to prevent revision conflicts within
the database will no longer work with multiple masters.

This is just a laws-of-physics thing: if you are doing independent updates
on disconnected nodes, you cannot enforce uniqueness of a value. You either
need some central locking service, or else you just deal with the non-unique
values afterwards.

The latter (relaxed) approach could be quite straightforward. e.g. when you
fetch a document by attribute foo using view_docs_by_foo, invoke it with
:limit=>2. If you get one document then there's no problem. If you get 2
then there is, and you can trigger a procedure by which either the user or
the system administrator has to sort it out.

If you are using the doc_id rather than an attribute, what you'll actually
find is two revisions of the document under the same doc_id, rather than two
different docs sharing the same attribute value. In principle you deal with
this in the same way.



View raw message