You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@couchdb.apache.org by sleepnova <wa...@gmail.com> on 2011/02/20 20:19:06 UTC

About _id generation rule

Hi,

Does any one know what is the CouchDB _id generation rule?
I'd like to generate it from my client.

-- 
- sleepnova

Re: About _id generation rule

Posted by Robert Newson <ro...@gmail.com>.
It's worth noting that couchdb only generates a _id if you don't
choose one for yourself. I'm often surprised when people assume that
they must use a uuid, and particularly surprised when they think they
have to use the ones we generate.

In the case that you simply don't care about the id of your documents
then by all means POST to the /db resource. Bear in mind that multiple
posts might occur if there's a problem (some browsers do this, iirc).
If you have a natural key, then it's usually better you use that,
especially if you need to detect conflicting updates.

B.

On 20 February 2011 19:59, Dmitry Unkovsky <oi...@gmail.com> wrote:
> As I can grasp in src/couchdb/coudh_uuids.erl, dependent on chosen
> uuids algo in config you either take
> a) random 16 bytes;
> or b) 14 hex-microseconds digits catenated with 9 randomly generated bytes;
> or c) 13 bytes of semi-constant prefix concatenated with 6 hex digits
> incremented by rand(1,0xffe), where prefix is randomly updated once
> total increment is greater than 0xfff000.
>
> No other kind of tricks. I'd just make sure my ids would not easily
> overlap, probably java uuids should be good enough.
>
> On 20 February 2011 21:48, sleepnova <wa...@gmail.com> wrote:
>> Ha, I know the host uuids request trick.
>> But it doesn't solve my problem, I need to generate it offline.
>> Right now I use Java API to generate UUID and strip all "-" in it to
>> make it looks like an _id generated by CouchDB.
>> But I wonder if this approach is good enough, or there are some better
>> way to make my _id more appropriate.
>> Because I don't know if Couch plays any trick on the auto generated
>> _id that could make some different to the internal storage.
>>
>> 2011/2/21 Bill Barry <bi...@billbarry.org>:
>>> On Sun, Feb 20, 2011 at 11:19 AM, sleepnova <wa...@gmail.com> wrote:
>>>
>>>> Hi,
>>>>
>>>> Does any one know what is the CouchDB _id generation rule?
>>>> I'd like to generate it from my client.
>>>>
>>>>
>>> Not to directly answer your question because I don't know how CouchDB
>>> generates the UUIDs, but any UUID generator should work. You can also
>>> request them from the host using a GET to /_uuids  or if you want 10 of
>>> them   /_uuids?count=10
>>>
>>> Bill
>>>
>>
>> --
>> - sleepnova
>>
>
>
>
> --
> DU
>

Re: About _id generation rule

Posted by Dmitry Unkovsky <oi...@gmail.com>.
As I can grasp in src/couchdb/coudh_uuids.erl, dependent on chosen
uuids algo in config you either take
a) random 16 bytes;
or b) 14 hex-microseconds digits catenated with 9 randomly generated bytes;
or c) 13 bytes of semi-constant prefix concatenated with 6 hex digits
incremented by rand(1,0xffe), where prefix is randomly updated once
total increment is greater than 0xfff000.

No other kind of tricks. I'd just make sure my ids would not easily
overlap, probably java uuids should be good enough.

On 20 February 2011 21:48, sleepnova <wa...@gmail.com> wrote:
> Ha, I know the host uuids request trick.
> But it doesn't solve my problem, I need to generate it offline.
> Right now I use Java API to generate UUID and strip all "-" in it to
> make it looks like an _id generated by CouchDB.
> But I wonder if this approach is good enough, or there are some better
> way to make my _id more appropriate.
> Because I don't know if Couch plays any trick on the auto generated
> _id that could make some different to the internal storage.
>
> 2011/2/21 Bill Barry <bi...@billbarry.org>:
>> On Sun, Feb 20, 2011 at 11:19 AM, sleepnova <wa...@gmail.com> wrote:
>>
>>> Hi,
>>>
>>> Does any one know what is the CouchDB _id generation rule?
>>> I'd like to generate it from my client.
>>>
>>>
>> Not to directly answer your question because I don't know how CouchDB
>> generates the UUIDs, but any UUID generator should work. You can also
>> request them from the host using a GET to /_uuids  or if you want 10 of
>> them   /_uuids?count=10
>>
>> Bill
>>
>
> --
> - sleepnova
>



-- 
DU

Re: About _id generation rule

Posted by sleepnova <wa...@gmail.com>.
Ha, I know the host uuids request trick.
But it doesn't solve my problem, I need to generate it offline.
Right now I use Java API to generate UUID and strip all "-" in it to
make it looks like an _id generated by CouchDB.
But I wonder if this approach is good enough, or there are some better
way to make my _id more appropriate.
Because I don't know if Couch plays any trick on the auto generated
_id that could make some different to the internal storage.

2011/2/21 Bill Barry <bi...@billbarry.org>:
> On Sun, Feb 20, 2011 at 11:19 AM, sleepnova <wa...@gmail.com> wrote:
>
>> Hi,
>>
>> Does any one know what is the CouchDB _id generation rule?
>> I'd like to generate it from my client.
>>
>>
> Not to directly answer your question because I don't know how CouchDB
> generates the UUIDs, but any UUID generator should work. You can also
> request them from the host using a GET to /_uuids  or if you want 10 of
> them   /_uuids?count=10
>
> Bill
>

-- 
- sleepnova

Re: About _id generation rule

Posted by Bill Barry <bi...@billbarry.org>.
On Sun, Feb 20, 2011 at 11:19 AM, sleepnova <wa...@gmail.com> wrote:

> Hi,
>
> Does any one know what is the CouchDB _id generation rule?
> I'd like to generate it from my client.
>
>
Not to directly answer your question because I don't know how CouchDB
generates the UUIDs, but any UUID generator should work. You can also
request them from the host using a GET to /_uuids  or if you want 10 of
them   /_uuids?count=10

Bill