couchdb-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Daniel Itaboraí <itabora...@gmail.com>
Subject Re: Validate uniqueness field
Date Mon, 29 Mar 2010 16:06:06 GMT
Distributed uniqueness is a hard problem, but since you intend to use it
only on a single node, perhaps you should create a view for each set of
fields that you intend to be unique in your documents.You would emit the
unique combination of values as the key and the document id as the value.
For the reduce function, you should just count the number of documents that
hold that particular key.

Prior to each PUT or POST on a document, you should query the view to make
sure that no other document has used that specific combination of values
(the reduced value should be 0). Also, after each PUT or POST, you´d have to
query it again to see if the uniqueness still holds (the reduced value
should be 1).

If the probability of two or more writers issuing operations that might
violate the uniqueness constraint is low enough, you might be able to get
away with it. This, of course, has a race condition (aside from also being
slow, ugly and discouraged). You would have to periodically handle
uniqueness violations either automatically or manually.

I think you should ask yourself first what´s the worst that could happen
when a violation of a uniqueness constraint happens. Sometimes you can just
work around it.


regards,
Daniel Itaboraí

On Sun, Mar 28, 2010 at 12:41 AM, faust 1111 <faust451@gmail.com> wrote:

> Why too documents?
> But i have one issue User
>  i need only one document .
>
> i am interesting, how couch people do in real projects.
> when they need  two unique fields in document.
>
>
> 2010/3/28 Jan Lehnardt <jan@apache.org>:
> > You need to have two documents with a unique ID each.
> >
> > Cheers
> > Jan
> > --
> >
> > On 27 Mar 2010, at 17:12, faust 1111 wrote:
> >
> >> but what if i have two unique fields
> >>  login
> >>  email
> >>
> >> 2010/3/28 J Chris Anderson <jchris@gmail.com>:
> >>>
> >>> On Mar 27, 2010, at 4:56 PM, faust 1111 wrote:
> >>>
> >>>> Hi
> >>>>
> >>>> In what way i cat implement validation of uniqueness?
> >>>> User
> >>>>  email: unique
> >>>>  login:  unique
> >>>>
> >>>
> >>> You can only have 1 unique field per database. you implement it by
> using it as a docid, like
> >>>
> >>> {
> >>> "_id" : "user:unique",
> >>>   ...
> >>> }
> >>>
> >>> Chris
> >
> >
>

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message