best practice on document identifiers if using UUID as IDs?

134 views
Skip to first unread message

atom992

unread,
Jun 15, 2015, 12:25:55 PM6/15/15
to mobile-c...@googlegroups.com


I am thinking about how long should I design the length of document IDs. As we know,All document meta‐ data, including the document ID, is stored in memory at all times, so longer IDs make for a larger RAM footprint, which reduces the RAM available for caching the document data. but too short IDs might not be sure unique. so for the best practice, how long should I design the length of doc IDs.

Jens Alfke

unread,
Jun 15, 2015, 2:03:22 PM6/15/15
to mobile-c...@googlegroups.com

> On Jun 15, 2015, at 9:25 AM, atom992 <yangzi...@gmail.com> wrote:
>
> I am thinking about how long should I design the length of document IDs. As we know,All document meta‐ data, including the document ID, is stored in memory at all times

That’s not true; where did you read that?

> but too short IDs might not be sure unique. so for the best practice, how long should I design the length of doc IDs.

It depends on your needs. If you don’t care what the docID looks like but it has to be unique, just use Database.createDocument, which will generate a random UUID.

If you do care about the docID, you can come up with unique ones that are a lot shorter. For example, if you need a unique ID for a user’s profile document, just use “profile:”+username. If you need a document for a particular product in your inventory, just use its SKU or UPC number.

—Jens

atom992

unread,
Jun 15, 2015, 9:41:19 PM6/15/15
to mobile-c...@googlegroups.com
1. from the book <Developing with Couchbase Server> on page 34 from oreilly which ISBN is 978-1-449-33116-0 by MC Brown.
2. If I use REST api to create doc, what is the best practice to generate UUID as ID?
As long as possible or The shorter, the better?

Jens Alfke

unread,
Jun 15, 2015, 11:22:06 PM6/15/15
to mobile-c...@googlegroups.com
On Jun 15, 2015, at 6:41 PM, atom992 <yangzi...@gmail.com> wrote:

1. from the book <Developing with Couchbase Server> on page 34 from oreilly which ISBN is 978-1-449-33116-0 by MC Brown.

Couchbase Server is not the same thing as Couchbase Lite.

Also, that book is from 2013 so it probably covers Couchbase Server 2.0. Newer versions, 2.5 and later, are much better at handling buckets whose size exceeds available RAM.

2. If I use REST api to create doc, what is the best practice to generate UUID as ID?

POST the document properties to /db.

—Jens
Reply all
Reply to author
Forward
0 new messages