First of all, I'd like to say that CouchDB is an amazing project. I've been
following it for a year and have recently made it a first class citizen of
my framework.
Anyways, looked for this answer but I couldn't find it.
Let's say I want to create a database that contains the pages in a wiki.
Each document looks something like this:
{
name: 'about_us',
body: 'This is the about us page'
}
There would be a view on the database where the key is 'name'.
The problem is this:
User A goes to create the 'aboutus' page. We want it to be unique so we
check if it is in the view. Since it is the first 'about_us' page, we can't
find it. So we are about to do the insert but haven't started yet.
In the meantime, User B goes to create the 'aboutus' page. We check the view
and it also isn't there yet because User A has not completed its insert. We
start to do the insert for User B.
In this case, both User A and User B have begun the insert process.
At the end of the inserts, we will have two documents with the same name
'aboutus'. Can this be prevented?
I know I can put the 'name' in the '_id' field but I'd like to avoid it
because I'm abstracting CouchDB and the abstraction does not allow for it.
Anybody have any solutions other than making 'name' the '_id' field?
-Sunny