You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@couchdb.apache.org by faust 1111 <fa...@gmail.com> on 2010/04/19 12:01:58 UTC

Short ids in url.

Hi guy's.

i need short integer ids in url  like host/audios/23342
how couch guy's catch this?

Thanks.

Re: Short ids in url.

Posted by Robert Newson <ro...@gmail.com>.
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
<se...@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 <fa...@gmail.com>:
>>> I need autogenerated short ids.
>>> i try use rand(99999999) is it fine?
>>>
>>> 2010/4/19 David Coallier <da...@gmail.com>:
>>>> On 19 April 2010 11:19, faust 1111 <fa...@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
>>>>
>>>
>
>

Re: Short ids in url.

Posted by Sebastian Cohnen <se...@googlemail.com>.
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 <fa...@gmail.com>:
>> I need autogenerated short ids.
>> i try use rand(99999999) is it fine?
>> 
>> 2010/4/19 David Coallier <da...@gmail.com>:
>>> On 19 April 2010 11:19, faust 1111 <fa...@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
>>> 
>> 


Re: Short ids in url.

Posted by faust 1111 <fa...@gmail.com>.
is it possible send couch like /_uuids?count=10
and its return me  short ids?

2010/4/19 faust 1111 <fa...@gmail.com>:
> I need autogenerated short ids.
> i try use rand(99999999) is it fine?
>
> 2010/4/19 David Coallier <da...@gmail.com>:
>> On 19 April 2010 11:19, faust 1111 <fa...@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
>>
>

Re: Short ids in url.

Posted by faust 1111 <fa...@gmail.com>.
I need autogenerated short ids.
i try use rand(99999999) is it fine?

2010/4/19 David Coallier <da...@gmail.com>:
> On 19 April 2010 11:19, faust 1111 <fa...@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
>

Re: Short ids in url.

Posted by David Coallier <da...@gmail.com>.
On 19 April 2010 11:19, faust 1111 <fa...@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

Re: Short ids in url.

Posted by faust 1111 <fa...@gmail.com>.
yes i know that i can create my own ids
but i am interesting in what way couch guy's solve this.

2010/4/19 David Coallier <da...@gmail.com>:
>>
>> i need short integer ids in url  like host/audios/23342
>> how couch guy's catch this?
>
> You'd have to create your own IDs when creating a new document.
>
> Check out the PUT part of the document API where you specify a document id:
> http://wiki.apache.org/couchdb/HTTP_Document_API
>
> This should help you :)
>
>
> --
> David Coallier
>

Re: Short ids in url.

Posted by David Coallier <da...@gmail.com>.
>
> i need short integer ids in url  like host/audios/23342
> how couch guy's catch this?

You'd have to create your own IDs when creating a new document.

Check out the PUT part of the document API where you specify a document id:
http://wiki.apache.org/couchdb/HTTP_Document_API

This should help you :)


-- 
David Coallier