10.1. Document Design Considerations

When designing your database, and your document structure, there are a number ofbest practices to take into consideration. Especially for people accustomed torelational databases, some of these techniques may be non-obvious.

10.1.1. Don’t rely on CouchDB’s auto-UUID generation

While CouchDB will generate a unique identifier for the _id field of any docthat you create, in most cases you are better off generating them yourself fora few reasons:

  • If for any reason you miss the 200 OK reply from CouchDB, and storing thedocument is attempted again, you would end up with the same document contentstored under duplicate _ids. This could easily happen with intermediaryproxies and cache systems that may not inform developers that the failedtransaction is being retried.
  • _ids are are the only unique enforced value within CouchDB so you mightas well make use of this. CouchDB stores its documents in a B+ tree. Eachadditional or updated document is stored as a leaf node, and may requirere-writing intermediary and parent nodes. You may be able to take advantage ofsequencing your own ids more effectively than the automatically generated idsif you can arrange them to be sequential yourself.

10.1.2. Alternatives to auto-incrementing sequences

Because of replication, as well as the distributed nature of CouchDB, it is notpractical to use auto-incrementing sequences with CouchDB. These are often usedto ensure unique identifiers for each row in a database table. CouchDB generatesunique ids on its own and you can specify your own as well, so you don’t reallyneed a sequence here. If you use a sequence for something else, you will bebetter off finding another way to express it in CouchDB in another way.

原文: http://docs.couchdb.org/en/stable/best-practices/documents.html