I want absolute atomicity on a single couchdb instance (insert, fail if already existing)

Posted by MatternPatching on Stack Overflow See other posts from Stack Overflow or by MatternPatching
Published on 2011-01-07T08:36:46Z Indexed on 2011/01/08 20:54 UTC
Read the original article Hit count: 203

Filed under:

I've come to really love the couchdb style of organizing and updating data, but there are a few situations where I really need to be able to create an entry and determine if an equivalent entry is already in existence before returning to the user. The only situation that this is absolutely necessary for my application is user registration. I'm fine with having all user registration writes go to a particular, designated couchdb instance known as the "registration-instance".

I want to hash the user_id into some _id to use. Then execute a put with this _id, but fail if the _id is already inserted. I need to return to the user that the user name is already reserved, and I cannot detect the conflict later and resolve it at that point, because the user would be under the impression that they had reserved the user name.

I don't see why couchdb couldn't provide some way to do this, under the assumption that you designate that inserts for a particular "type" of document always are routed to a particular instance.

© Stack Overflow or respective owner

Related posts about couchdb