couchdb-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Wout Mertens <wout.mert...@gmail.com>
Subject Please allow _prefix for auto-created _id
Date Sat, 07 Mar 2009 11:58:49 GMT
Hi devs,

Would it be possible to allow a _prefix parameter to be given when  
creating a new document, which would be used for auto-generating an _id?

The reason I ask is that it's much harder to create a unique  
descriptive id in an application than in a database.

In my application I have to create sessions in response to user  
queries, and I can't generate a reasonably compact _id that's  
guaranteed to be unique, at least not easily. If I could just give  
CouchDB a _prefix instead of an _id, CouchDB could generate a  
descriptive, compact, guaranteed unique _id for me instead.

E.g. I could create an _id as follows:

$ perl -e 'print "session_".crypt(join("",POSIX::uname).$ 
$.time,"42")."\n"'
session_42/xjrVvFTocQ

This seems ok at first but then it turns out that crypt only uses the  
first 8 characters and this therefore always gives the same result. So  
I have to use MD5, which means another module or at least imported  
functions etc.

OR, I could simply add "_prefix":"session_" to the JSON and CouchDB  
would return something like
session_91a92205f9e6df704fdcca5968a3cdfb for the _id. No extra code  
from me, guaranteed unique, easy to remember.

Is this a convincing use case? :-D

I think that a prefix+unique suffix allows you to have a natural key  
for lists of data. When you see that UUID referenced somewhere else,  
just like a natural key, you immediately understand the function of  
that reference.

Thanks,

Wout.

Mime
View raw message