couchdb-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Zachary Zolton <zachary.zol...@gmail.com>
Subject Re: Ensuring unique attributes across documents?
Date Thu, 12 Nov 2009 02:14:39 GMT
You COULD use the User document's ID to ensure uniqueness. The second
PUT to the same database URL would result in an HTTP 409 status code.

Here it is on StackOverflow:
http://stackoverflow.com/questions/1058258/does-couchdb-support-unqiue-key-constraint


On Wed, Nov 11, 2009 at 7:00 PM, Cory Nelson <phrosty@gmail.com> wrote:
> Hello,
>
> I'm trying to implement a typical user signup operation: when you
> finally add a user to the database, you want it to have both a unique
> user name, and a unique email.  In SQL I'd do something like:
>
> BEGIN TRANSACTION ISOLATION LEVEL SERIALIZABLE
>
> count = SELECT COUNT(*) FROM t_users WHERE name=? OR email=?
>
> if(count == 0)
> {
> INSERT INTO t_users VALUES(...)
> COMMIT
> }
> else
> {
> ROLLBACK
> }
>
> Can anyone give an example of how to achieve the same thing in CouchDB?
>
> --
> Cory Nelson
>

Mime
View raw message