Greetings,

>So, I've got a situation where I want to maintain a CouchDB database
>of users that have a user name and email address. Given that the user
>name needs to be unique—and is significant to my URL scheme—I've
>chosen to use that as the document ID.

While I don't know the full context of your situation, I would still use a 
generated id for users. This makes life much easier in the software's life 
cycle. For example, what if you want to do away with user names and just use 
e-mail addresses? Or you need to generically identify a user but don't have 
access to their user name? Now you need to re-rig your code to use a different 
id scheme. I've found it much easier to just take the user id generated by the 
index or my code's logic and use that as my primary identifier in the database. 
I've found this to be database agnostic.

>However, I'd also like to maintain uniqueness of the email addresses
>across users... Any ideas about how to best accomplish this?

While those with more experience than me on the Couch may have a better 
technique, I have always just constructed a view that outputs the users' email 
addresses as keys. Then I can query the view with ?key='emailInQuestion' and if 
the returned array has any results then the e-mail is already registered. This 
also scales nicely with cases where users can have more than one email 
associated to them.

--
Sam Bisbee



Reply via email to