incubator-couchdb-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Robert Newson <robert.new...@gmail.com>
Subject Re: Short ids in url.
Date Mon, 19 Apr 2010 13:24:51 GMT
You could also do this;

1) GET /db/my_counter_doc
1a) if 404, PUT /db/my_counter_doc -d '{"counter":0"}'
1b) if 200, PUT /db/my_counter_doc -d '{"counter":counter+N",
"_rev":"rev from 1a"}'
1c) repeat step 1 if 1b returned 409.
2) use numbers from counter to counter+N for doc ids.

This is a common alternative to using auto-increment columns in RDBMS's too.

B.

On Mon, Apr 19, 2010 at 1:57 PM, Sebastian Cohnen
<sebastiancohnen@googlemail.com> wrote:
> no, UUIDs need to be as unique as possible. couchdb's _uuid API guarantees a high entropy
for the produced IDs. the problem with (short) numeric IDs is, that they are more likely to
produce collisions. if you do not use replication, you can basically do this:
>
> 1) create a number on your client
> 2) try to insert your document using this id
> 3) if you get a conflict, goto 1)
> 4) if your insert was successful, you are done.
>
> the fundamental flaw to this approach is, that you more likely get conflicts when using
replication (the shorter the IDs are, the more likely of course, see http://en.wikipedia.org/wiki/Birthday_attack#The_mathematics).
>
>
> On 19.04.2010, at 14:48, faust 1111 wrote:
>
>> is it possible send couch like /_uuids?count=10
>> and its return me  short ids?
>>
>> 2010/4/19 faust 1111 <faust451@gmail.com>:
>>> I need autogenerated short ids.
>>> i try use rand(99999999) is it fine?
>>>
>>> 2010/4/19 David Coallier <david.coallier@gmail.com>:
>>>> On 19 April 2010 11:19, faust 1111 <faust451@gmail.com> wrote:
>>>>> yes i know that i can create my own ids
>>>>> but i am interesting in what way couch guy's solve this.
>>>>>
>>>>
>>>> Right... I'm not sure I exactly understand what you mean. Do you mean
>>>> how could one do that from within CouchDB using autogenerated IDs or
>>>> using something like "io" (http://github.com/janl/io) which is a short
>>>> url generator using CouchDB :)
>>>>
>>>>
>>>>
>>>> --
>>>> David Coallier
>>>>
>>>
>
>

Mime
View raw message