You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@couchdb.apache.org by Olaf Kr��ger <ok...@apache.org> on 2020/07/10 12:03:09 UTC
Don���t rely on CouchDB���s auto-UUID generation?
Hi guys,
before reading the docs I was afraid of creating custom _ids.
But the docs [1] even says that we shouldn't rely on the auto generated UUID.
Our primary goal is to create more human readable _ids.
So, in order to avoid conflicts, the idea is to introduce scoped custom _ids which starts e.g. with a leading namespace followed by a short id, e.g.:
INV-HG6FU
(The length of the short id depends on the expected number of documents for a certain scope/doc type)
However, before going this way I would like to know if there are any drawbacks with such approach and how others achieve this.
Or should we rather rely on the auto-UUID and move custom ids into its own document property, something like e.g. "publicId"?
Many thanks in advance!
Olaf
[1]
https://docs.couchdb.org/en/stable/best-practices/documents.html#don-t-rely-on-couchdb-s-auto-uuid-generation
Re: Don’t rely on CouchDB’s auto-UUID generation?
Posted by Stefan Klein <st...@gmail.com>.
Hi,
Am Fr., 10. Juli 2020 um 14:03 Uhr schrieb Olaf Krüger <ok...@apache.org>:
> However, before going this way I would like to know if there are any drawbacks with such approach and how others achieve this.
> Or should we rather rely on the auto-UUID and move custom ids into its own document property, something like e.g. "publicId"?
Since the document id is the only way to enforce uniqueness, if our
data has a "natural" id, like a serial number we use that as the
document id (with a pre / postfix).
If the data doesn't have a "natural" id, we generate an uuid, still
with a pre/postfix and use this.
You might want to read about partitioned databases¹ and see if you
might consider using those in the foreseeable future to plan your
document id generation according to those requirements.
regards,
Stefan
[1] https://docs.couchdb.org/en/stable/partitioned-dbs/index.html
Re: Don’t rely on CouchDB’s auto-UUID generation?
Posted by Jan Lehnardt <ja...@apache.org>.
Hi Olaf,
> On 10. Jul 2020, at 14:03, Olaf Krüger <ok...@apache.org> wrote:
>
> Hi guys,
>
> before reading the docs I was afraid of creating custom _ids.
> But the docs [1] even says that we shouldn't rely on the auto generated UUID.
>
> Our primary goal is to create more human readable _ids.
> So, in order to avoid conflicts, the idea is to introduce scoped custom _ids which starts e.g. with a leading namespace followed by a short id, e.g.:
>
> INV-HG6FU
>
> (The length of the short id depends on the expected number of documents for a certain scope/doc type)
>
> However, before going this way I would like to know if there are any drawbacks with such approach and how others achieve this.
This is a fine approach. The only drawback is when your expectation ends up not holding, but then you could just lengthen the id one by one to get more space.
> Or should we rather rely on the auto-UUID and move custom ids into its own document property, something like e.g. "publicId”?
This also works, bur your original idea is also fine.
—
I think what the docs want to convey is that avoiding accidental duplicates on network-retries is the main reason for this advice. You can also retrieve UUIDs from CouchDB’s to assign to docs on the client if you don’t have your own.
In addition, CouchDB’s default UUID scheme produces UUIDs in sequential batches[1], that make inserts more efficient. If you can reproduce this in your external IDs, your get the same benefits.
[1]: https://github.com/apache/couchdb/blob/master/rel/overlay/etc/default.ini#L372-L375
Best
Jan
—
Professional Support for Apache CouchDB:
https://neighbourhood.ie/couchdb-support/
>
> Many thanks in advance!
>
> Olaf
>
> [1]
> https://docs.couchdb.org/en/stable/best-practices/documents.html#don-t-rely-on-couchdb-s-auto-uuid-generation
>
>
Re: Don���������t rely on CouchDB���������s auto-UUID generation?
Posted by Olaf Kr��ger <ok...@apache.org>.
Wow, thanks Jan and Stefan for your quick responses!
Very helpful!
Olaf