{"id":10226,"date":"2025-08-04T08:56:24","date_gmt":"2025-08-04T15:56:24","guid":{"rendered":"https:\/\/www.couchbase.com\/developers\/tutorials\/document-key-design\/"},"modified":"2025-08-04T08:56:24","modified_gmt":"2025-08-04T15:56:24","slug":"document-key-design","status":"publish","type":"tutorials","link":"https:\/\/www.couchbase.com\/de\/developers\/tutorials\/document-key-design\/","title":{"rendered":"Document Key Design"},"content":{"rendered":"<p class=\"wp-block-paragraph\">An important part of JSON database modeling is how to design document keys. There are different patterns as mentioned below when it comes to designing a document key.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Prefixing<\/li>\n\n\n<li>Predictable<\/li>\n\n\n<li>Counter ID<\/li>\n\n\n<li>Unpredictable<\/li>\n\n\n<li>Combinations<\/li>\n\n<\/ul>\n\n\n\n<h3 id=\"h-prefixing\" class=\"wp-block-heading\">Prefixing<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Remember that in Couchbase, different types of documents should be stored in separate collections. For example, users, orders, and products should each have their own collection within a scope. You do not need prefixing to isolate document types.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">However, if you want to use prefixing for other purposes, pick a delimiter, and be consistent throughout your enterprise. For instance, you might use any of these approaches: <code>myPrefix:123<\/code>, <code>myPrefix_123<\/code>, oder <code>myPrefix::123<\/code>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">You may also use a prefix as a combination of two other documents (similar to a composite key), in order to store information on the relationship between those documents.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">For instance:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>123::987<\/code> im <code>studentEnrollment<\/code> collection may be a document with information about student 123&#8217;s enrollment in class 987.<\/li>\n\n<\/ul>\n\n\n\n<h3 id=\"h-predictable\" class=\"wp-block-heading\">Predictable<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Let&#8217;s say we&#8217;re storing a user profile. Assuming no cookies, what are we guaranteed to know about our user after they&#8217;ve logged in? Well, one thing would be their login name.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">To make life easy for ourselves in retrieving the user profile, key it with that user&#8217;s login name. Everything else we need to know about that person could be derived from their user profile, in one way or another.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">But since keys are immutable, for a user to change their login name, we now have to either create a new user profile under a new key or create a look-up document. We could insist that our users can never change their login names but it&#8217;s unreasonable to make our users suffer unnecessarily.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The main downside of a predictable key is that, usually, it&#8217;ll be an element of the data that we&#8217;re storing.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><img decoding=\"async\" src=\".\/assets\/predictable_key.png\" alt=\"Predictable Key\"><\/p>\n\n\n\n<h3 id=\"h-counter-id\" class=\"wp-block-heading\">Counter ID<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">We can get Couchbase to generate a numeric key by using a counter. If you&#8217;re using a counter ID pattern, every insert (not update) requires 2 mutations. One to increment a counter document and the other to mutate the document.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Here&#8217;s how it works:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Someone fills out the new user account form and clicks &#8220;Submit&#8221;.<\/li>\n\n\n<li>Increment our counter document and it returns the next number up (e.g. 123).<\/li>\n\n\n<li>Create a new user profile document keyed with 123.<\/li>\n\n\n<li>Create look-up documents for things such as their user id, enabling us to do a simple look-up on the data we hold at login time.<\/li>\n\n<\/ol>\n\n\n\n<p class=\"wp-block-paragraph\"><img decoding=\"async\" src=\".\/assets\/counter_key.png\" alt=\"Counter Key\"><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">We also get some additional benefits from this pattern, such as a counter providing us with some details of many user profiles we&#8217;ve created during the application&#8217;s lifetime.<\/p>\n\n\n\n<h3 id=\"h-unpredictable\" class=\"wp-block-heading\">Unpredictable<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">This pattern uses system generated unique IDs like UUID.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><img decoding=\"async\" src=\".\/assets\/unpredictable_key.png\" alt=\"Unpredictable Key\"><\/p>\n\n\n\n<h3 id=\"h-combinations\" class=\"wp-block-heading\">Combinations<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Combining these methods can lead to the optimal strategy for your application.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">We&#8217;ve looked before at when to embed data in one large document and when it&#8217;s best to refer to other documents. When we choose to refer to data held in separate documents, we can build predictable key names from components that tell us something about what the document holds.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Let&#8217;s look at our user profile again. The main document is stored under the key 1001. We&#8217;re working on an ecommerce site so we also want to know all of the orders our customer has made. Simple: we store the list of orders under the key <code>1001:orders<\/code> in a <code>customerOrders<\/code> collection.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Similarly, our system might judge what sort of marketing emails to send to customers based on their total spend with the site. Rather than have the system calculate that each time, it can be calculated once and then stored for later retrieval under the key <code>1001:orders:value<\/code> in a <code>customerOrdersTotalSpend<\/code> collection.<\/p>","protected":false},"excerpt":{"rendered":"<p>An important part of JSON database modeling is how to design document keys. There are different patterns as mentioned below when it comes to designing a document key. Prefixing Remember that in Couchbase, different types of documents should be stored in separate collections. For example, users, orders, and products should each have their own collection [&hellip;]<\/p>\n","protected":false},"author":0,"featured_media":0,"menu_order":0,"template":"","meta":{"_acf_changed":false,"inline_featured_image":false,"_acf":"","footnotes":""},"tutorial-languages":[551],"tutorial-tags":[565],"tutorial-technologies":[562,548,554],"tutorial-types":[555],"class_list":["post-10226","tutorials","type-tutorials","status-publish","hentry","tutorial-languages-any","tutorial-tags-data-modeling","tutorial-technologies-capella","tutorial-technologies-kv","tutorial-technologies-server","tutorial-types-tutorial"],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v28.8 (Yoast SEO v28.9) - https:\/\/yoast.com\/product\/yoast-seo-premium-wordpress\/ -->\n<title>Document Key Design - Couchbase<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.couchbase.com\/de\/developers\/tutorials\/document-key-design\/\" \/>\n<meta property=\"og:locale\" content=\"de_DE\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Document Key Design\" \/>\n<meta property=\"og:description\" content=\"An important part of JSON database modeling is how to design document keys. There are different patterns as mentioned below when it comes to designing a document key. Prefixing Remember that in Couchbase, different types of documents should be stored in separate collections. For example, users, orders, and products should each have their own collection [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.couchbase.com\/de\/developers\/tutorials\/document-key-design\/\" \/>\n<meta property=\"og:site_name\" content=\"Couchbase\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/Couchbase\/\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.couchbase.com\/wp-content\/uploads\/2026\/10\/Cloud-2.png\" \/>\n\t<meta property=\"og:image:width\" content=\"2548\" \/>\n\t<meta property=\"og:image:height\" content=\"1171\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:site\" content=\"@couchbase\" \/>\n<meta name=\"twitter:label1\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data1\" content=\"3\u00a0Minuten\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.couchbase.com\\\/de\\\/developers\\\/tutorials\\\/document-key-design\\\/\",\"url\":\"https:\\\/\\\/www.couchbase.com\\\/de\\\/developers\\\/tutorials\\\/document-key-design\\\/\",\"name\":\"Document Key Design - Couchbase\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.couchbase.com\\\/de\\\/#website\"},\"datePublished\":\"2025-08-04T15:56:24+00:00\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.couchbase.com\\\/de\\\/developers\\\/tutorials\\\/document-key-design\\\/#breadcrumb\"},\"inLanguage\":\"de\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.couchbase.com\\\/de\\\/developers\\\/tutorials\\\/document-key-design\\\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.couchbase.com\\\/de\\\/developers\\\/tutorials\\\/document-key-design\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.couchbase.com\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Document Key Design\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.couchbase.com\\\/de\\\/#website\",\"url\":\"https:\\\/\\\/www.couchbase.com\\\/de\\\/\",\"name\":\"Couchbase\",\"description\":\"The Operational Data Platform for AI\u2122\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.couchbase.com\\\/de\\\/#organization\"},\"alternateName\":\"Couchbase, Inc.\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.couchbase.com\\\/de\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"de\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/www.couchbase.com\\\/de\\\/#organization\",\"name\":\"Couchbase\",\"alternateName\":\"Couchbase, Inc.\",\"url\":\"https:\\\/\\\/www.couchbase.com\\\/de\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"de\",\"@id\":\"https:\\\/\\\/www.couchbase.com\\\/de\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/www.couchbase.com\\\/wp-content\\\/uploads\\\/2026\\\/11\\\/Couchbase_Logo_Couchbase_Token_Red-1.png\",\"contentUrl\":\"https:\\\/\\\/www.couchbase.com\\\/wp-content\\\/uploads\\\/2026\\\/11\\\/Couchbase_Logo_Couchbase_Token_Red-1.png\",\"width\":1129,\"height\":1129,\"caption\":\"Couchbase\"},\"image\":{\"@id\":\"https:\\\/\\\/www.couchbase.com\\\/de\\\/#\\\/schema\\\/logo\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/www.facebook.com\\\/Couchbase\\\/\",\"https:\\\/\\\/x.com\\\/couchbase\",\"https:\\\/\\\/www.youtube.com\\\/c\\\/CouchbaseServer\",\"https:\\\/\\\/www.linkedin.com\\\/company\\\/couchbase\\\/\",\"https:\\\/\\\/github.com\\\/couchbase\\\/\",\"https:\\\/\\\/en.wikipedia.org\\\/wiki\\\/Couchbase,_Inc.\"],\"description\":\"Couchbase is a database software company headquartered in San Jose, California, providing an operational data platform for AI used by hundreds of global enterprises.\",\"legalName\":\"Couchbase, Inc.\",\"foundingDate\":\"2011-01-01\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"Document Key Design - Couchbase","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.couchbase.com\/de\/developers\/tutorials\/document-key-design\/","og_locale":"de_DE","og_type":"article","og_title":"Document Key Design","og_description":"An important part of JSON database modeling is how to design document keys. There are different patterns as mentioned below when it comes to designing a document key. Prefixing Remember that in Couchbase, different types of documents should be stored in separate collections. For example, users, orders, and products should each have their own collection [&hellip;]","og_url":"https:\/\/www.couchbase.com\/de\/developers\/tutorials\/document-key-design\/","og_site_name":"Couchbase","article_publisher":"https:\/\/www.facebook.com\/Couchbase\/","og_image":[{"width":2548,"height":1171,"url":"https:\/\/www.couchbase.com\/wp-content\/uploads\/2026\/10\/Cloud-2.png","type":"image\/png"}],"twitter_card":"summary_large_image","twitter_site":"@couchbase","twitter_misc":{"Est. reading time":"3\u00a0Minuten"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.couchbase.com\/de\/developers\/tutorials\/document-key-design\/","url":"https:\/\/www.couchbase.com\/de\/developers\/tutorials\/document-key-design\/","name":"Document Key Design - Couchbase","isPartOf":{"@id":"https:\/\/www.couchbase.com\/de\/#website"},"datePublished":"2025-08-04T15:56:24+00:00","breadcrumb":{"@id":"https:\/\/www.couchbase.com\/de\/developers\/tutorials\/document-key-design\/#breadcrumb"},"inLanguage":"de","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.couchbase.com\/de\/developers\/tutorials\/document-key-design\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.couchbase.com\/de\/developers\/tutorials\/document-key-design\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.couchbase.com\/"},{"@type":"ListItem","position":2,"name":"Document Key Design"}]},{"@type":"WebSite","@id":"https:\/\/www.couchbase.com\/de\/#website","url":"https:\/\/www.couchbase.com\/de\/","name":"Couchbase","description":"The Operational Data Platform for AI\u2122","publisher":{"@id":"https:\/\/www.couchbase.com\/de\/#organization"},"alternateName":"Couchbase, Inc.","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.couchbase.com\/de\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"de"},{"@type":"Organization","@id":"https:\/\/www.couchbase.com\/de\/#organization","name":"Couchbase","alternateName":"Couchbase, Inc.","url":"https:\/\/www.couchbase.com\/de\/","logo":{"@type":"ImageObject","inLanguage":"de","@id":"https:\/\/www.couchbase.com\/de\/#\/schema\/logo\/image\/","url":"https:\/\/www.couchbase.com\/wp-content\/uploads\/2026\/11\/Couchbase_Logo_Couchbase_Token_Red-1.png","contentUrl":"https:\/\/www.couchbase.com\/wp-content\/uploads\/2026\/11\/Couchbase_Logo_Couchbase_Token_Red-1.png","width":1129,"height":1129,"caption":"Couchbase"},"image":{"@id":"https:\/\/www.couchbase.com\/de\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/Couchbase\/","https:\/\/x.com\/couchbase","https:\/\/www.youtube.com\/c\/CouchbaseServer","https:\/\/www.linkedin.com\/company\/couchbase\/","https:\/\/github.com\/couchbase\/","https:\/\/en.wikipedia.org\/wiki\/Couchbase,_Inc."],"description":"Couchbase ist ein in San Jose, Kalifornien, ans\u00e4ssiges Unternehmen f\u00fcr Datenbanksoftware, das eine operative Datenplattform f\u00fcr KI bereitstellt, die von Hunderten von globalen Unternehmen eingesetzt wird.","legalName":"Couchbase, Inc.","foundingDate":"2011-01-01"}]}},"acf":[],"permalink_manager":null,"_links":{"self":[{"href":"https:\/\/www.couchbase.com\/de\/wp-json\/wp\/v2\/tutorials\/10226","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.couchbase.com\/de\/wp-json\/wp\/v2\/tutorials"}],"about":[{"href":"https:\/\/www.couchbase.com\/de\/wp-json\/wp\/v2\/types\/tutorials"}],"version-history":[{"count":0,"href":"https:\/\/www.couchbase.com\/de\/wp-json\/wp\/v2\/tutorials\/10226\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.couchbase.com\/de\/wp-json\/wp\/v2\/media?parent=10226"}],"wp:term":[{"taxonomy":"tutorial-languages","embeddable":true,"href":"https:\/\/www.couchbase.com\/de\/wp-json\/wp\/v2\/tutorial-languages?post=10226"},{"taxonomy":"tutorial-tags","embeddable":true,"href":"https:\/\/www.couchbase.com\/de\/wp-json\/wp\/v2\/tutorial-tags?post=10226"},{"taxonomy":"tutorial-technologies","embeddable":true,"href":"https:\/\/www.couchbase.com\/de\/wp-json\/wp\/v2\/tutorial-technologies?post=10226"},{"taxonomy":"tutorial-types","embeddable":true,"href":"https:\/\/www.couchbase.com\/de\/wp-json\/wp\/v2\/tutorial-types?post=10226"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}