On 2 Jan 2009, at 15:34, A.J. Brown wrote:
I'm writing a proof of concept for our organization to use couchdb
for our content. Part of the task will be generating document Ids
from legacy Ids (autonumber integers). This would be done by
simply doing an md5() hash on the legacy id.
Since we're storing the same 32char hex string as our user-provided
document ids, When CouchDB generates an Id for a new document, will
it make sure that ID doesn't exist first? I know the chances of
generating the same exact ID are slim to none, but the question
still remains.
According to the documentation on the Wiki, POSTing to _uuids
retrieves a list of *unused* document IDs, so one would assume that it
does check to ensure the ID doesn't exist.
However, from reading the code it looks like *no* checks are actually
made (either when POSTing to _uuids or when POSTing to save a document
with autogenerated ID), but given that the UUID is securely randomly
generated the chances of a collision are so slim there is no point
worrying about it (see http://en.wikipedia.org/wiki/Universally_Unique_Identifier#Random_UUID_probability_of_duplicates)
. If a collision does occur, then I think all that would happen is
you would get a document update conflict error, perhaps someone more
familiar with the internals can confirm this?
Jason
--
Jason Davies
www.jasondavies.com