{"id":1797,"date":"2014-12-16T18:04:46","date_gmt":"2014-12-16T18:04:45","guid":{"rendered":"https:\/\/www.couchbase.com\/blog\/?p=1797"},"modified":"2023-06-28T01:19:02","modified_gmt":"2023-06-28T08:19:02","slug":"startkeydocid-behaviour","status":"publish","type":"post","link":"https:\/\/www.couchbase.com\/blog\/startkeydocid-behaviour\/","title":{"rendered":"`startkey_docid` Behaviour"},"content":{"rendered":"<p class=\"p1\"><span style=\"font-family: inherit;font-size: 1em;line-height: 1.4375em\">Today we had an interesting question pop up on Stack Overflow (<\/span><a href=\"https:\/\/stackoverflow.com\/q\/20083932\/98509\"><span style=\"line-height: 1\">https:\/\/stackoverflow.com\/q\/20083932\/98509<\/span><\/a><span style=\"font-family: inherit;font-size: 1em;line-height: 1.4375em\">) in relation to the correct usage of `<\/span><span class=\"s1\" style=\"font-family: inherit;font-size: 1em;line-height: 1.4375em\">startkey_docid`<\/span><span style=\"font-family: inherit;font-size: 1em;line-height: 1.4375em\">. The question was prompted as the user was passing in a valid `<\/span><span class=\"s1\" style=\"font-family: inherit;font-size: 1em;line-height: 1.4375em\">startkey`<\/span><span style=\"font-family: inherit;font-size: 1em;line-height: 1.4375em\"> and `<\/span><span class=\"s1\" style=\"font-family: inherit;font-size: 1em;line-height: 1.4375em\">startkey_docid`<\/span><span style=\"font-family: inherit;font-size: 1em;line-height: 1.4375em\">, however the `<\/span><span class=\"s1\" style=\"font-family: inherit;font-size: 1em;line-height: 1.4375em\">startkey_docid`<\/span><span style=\"font-family: inherit;font-size: 1em;line-height: 1.4375em\"> appeared to be ignored by the view. It is important to realized that the primary use case of the `<\/span><span class=\"s1\" style=\"font-family: inherit;font-size: 1em;line-height: 1.4375em\">startkey_docid`<\/span><span style=\"font-family: inherit;font-size: 1em;line-height: 1.4375em\"> is to allow you to paginate your view requests (see:\u00a0<\/span><span style=\"line-height: 1\"><a href=\"https:\/\/www.couchbase.com\/blog\/pagination-couchbase\/\">https:\/\/www.couchbase.com\/blog\/pagination-couchbase<\/a>)\u00a0<\/span><span style=\"font-family: inherit;font-size: 1em;line-height: 1.4375em\">by passing in a `<\/span><span class=\"s1\" style=\"font-family: inherit;font-size: 1em;line-height: 1.4375em\">startkey`<\/span><span style=\"font-family: inherit;font-size: 1em;line-height: 1.4375em\"> and `<\/span><span class=\"s1\" style=\"font-family: inherit;font-size: 1em;line-height: 1.4375em\">startkey_docid`<\/span><span style=\"font-family: inherit;font-size: 1em;line-height: 1.4375em\"> that matches the last document from your last page, which allows you to properly paginate in the case where numerous documents are emitting the same key. Since the correct usage of `<\/span><span class=\"s1\" style=\"font-family: inherit;font-size: 1em;line-height: 1.4375em\">startkey_docid`<\/span><span style=\"font-family: inherit;font-size: 1em;line-height: 1.4375em\"> is at the top of my mind, I figured this would be a good time to explain the behaviour for the future.<\/span><\/p>\n<p class=\"p2\">Here is a quick list of the important things to remember about `<span class=\"s1\">startkey_docid`<\/span>:<\/p>\n<ol class=\"ol1\">\n<li class=\"li3\"><span class=\"s1\">`startkey_docid`<\/span> will be entirely ignored if `<span class=\"s1\">startkey`<\/span> is ommitted.<\/li>\n<li class=\"li3\"><span class=\"s1\">`startkey_docid`<\/span> will only function correctly if you specify a `<span class=\"s1\">startkey`<\/span> which exactly matches documents which are indexed in the view.<\/li>\n<li class=\"li3\"><span class=\"s1\">`startkey_docid`<\/span> is expected to exactly match one of the docid&#8217;s in the results which exactly match your `<span class=\"s1\">startkey`<\/span>. If no match is made, the results will begin at the following key.<\/li>\n<\/ol>\n<p class=\"p2\">Pro-tip: If you need to verify how many exact matching rows are going to be returned for a particular `<span class=\"s1\">startkey`<\/span>, try first executing a view request with the `key` parameter rather than `startkey`.<\/p>\n<p class=\"p2\">P.S. The semantics for `<span class=\"s1\">endkey`<\/span> and `<span class=\"s1\">endkey_docid`<\/span> behave identically to `<span class=\"s1\">startkey`<\/span> and `<span class=\"s1\">startkey_docid`<\/span> as specified here.<\/p>\n<p class=\"p3\">Cheers, Brett<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Today we had an interesting question pop up on Stack Overflow (https:\/\/stackoverflow.com\/q\/20083932\/98509) in relation to the correct usage of `startkey_docid`. The question was prompted as the user was passing in a valid `startkey` and `startkey_docid`, however the `startkey_docid` appeared to [&hellip;]<\/p>\n","protected":false},"author":31,"featured_media":13873,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"inline_featured_image":false,"footnotes":""},"categories":[1],"tags":[],"ppma_author":[9004],"class_list":["post-1797","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-uncategorized"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v25.8 (Yoast SEO v25.8) - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>`startkey_docid` Behaviour - The Couchbase Blog<\/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\/blog\/startkeydocid-behaviour\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"`startkey_docid` Behaviour\" \/>\n<meta property=\"og:description\" content=\"Today we had an interesting question pop up on Stack Overflow (https:\/\/stackoverflow.com\/q\/20083932\/98509) in relation to the correct usage of `startkey_docid`. The question was prompted as the user was passing in a valid `startkey` and `startkey_docid`, however the `startkey_docid` appeared to [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.couchbase.com\/blog\/startkeydocid-behaviour\/\" \/>\n<meta property=\"og:site_name\" content=\"The Couchbase Blog\" \/>\n<meta property=\"article:published_time\" content=\"2014-12-16T18:04:45+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2023-06-28T08:19:02+00:00\" \/>\n<meta name=\"author\" content=\"Brett Lawson, Principal Software Engineer, Couchbase\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Brett Lawson, Principal Software Engineer, Couchbase\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/startkeydocid-behaviour\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/startkeydocid-behaviour\/\"},\"author\":{\"name\":\"Brett Lawson, Principal Software Engineer, Couchbase\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/#\/schema\/person\/5cfc2fbf25776be2a027a474562be02f\"},\"headline\":\"`startkey_docid` Behaviour\",\"datePublished\":\"2014-12-16T18:04:45+00:00\",\"dateModified\":\"2023-06-28T08:19:02+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/startkeydocid-behaviour\/\"},\"wordCount\":279,\"commentCount\":4,\"publisher\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/#organization\"},\"image\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/startkeydocid-behaviour\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2022\/11\/couchbase-nosql-dbaas.png\",\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/www.couchbase.com\/blog\/startkeydocid-behaviour\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/startkeydocid-behaviour\/\",\"url\":\"https:\/\/www.couchbase.com\/blog\/startkeydocid-behaviour\/\",\"name\":\"`startkey_docid` Behaviour - The Couchbase Blog\",\"isPartOf\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/startkeydocid-behaviour\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/startkeydocid-behaviour\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2022\/11\/couchbase-nosql-dbaas.png\",\"datePublished\":\"2014-12-16T18:04:45+00:00\",\"dateModified\":\"2023-06-28T08:19:02+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/startkeydocid-behaviour\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.couchbase.com\/blog\/startkeydocid-behaviour\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/startkeydocid-behaviour\/#primaryimage\",\"url\":\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2022\/11\/couchbase-nosql-dbaas.png\",\"contentUrl\":\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2022\/11\/couchbase-nosql-dbaas.png\",\"width\":1800,\"height\":630},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/startkeydocid-behaviour\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.couchbase.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"`startkey_docid` Behaviour\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/#website\",\"url\":\"https:\/\/www.couchbase.com\/blog\/\",\"name\":\"The Couchbase Blog\",\"description\":\"Couchbase, the NoSQL Database\",\"publisher\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.couchbase.com\/blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/#organization\",\"name\":\"The Couchbase Blog\",\"url\":\"https:\/\/www.couchbase.com\/blog\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/2023\/04\/admin-logo.png\",\"contentUrl\":\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/2023\/04\/admin-logo.png\",\"width\":218,\"height\":34,\"caption\":\"The Couchbase Blog\"},\"image\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/#\/schema\/logo\/image\/\"}},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/#\/schema\/person\/5cfc2fbf25776be2a027a474562be02f\",\"name\":\"Brett Lawson, Principal Software Engineer, Couchbase\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/#\/schema\/person\/image\/ee3586f0c112c20e863af447d44dec8f\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/6aec1ba24ef7558a248dcde7b7a18b15b06e2885b24b663906a448634066c1c4?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/6aec1ba24ef7558a248dcde7b7a18b15b06e2885b24b663906a448634066c1c4?s=96&d=mm&r=g\",\"caption\":\"Brett Lawson, Principal Software Engineer, Couchbase\"},\"description\":\"Brett Lawson is a Principal Software Engineer at Couchbase. Brett is responsible for the design and development of the Couchbase Node.js and PHP clients as well as playing a role in the design and development of the C library, libcouchbase.\",\"url\":\"https:\/\/www.couchbase.com\/blog\/author\/brett-lawson\/\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"`startkey_docid` Behaviour - The Couchbase Blog","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\/blog\/startkeydocid-behaviour\/","og_locale":"en_US","og_type":"article","og_title":"`startkey_docid` Behaviour","og_description":"Today we had an interesting question pop up on Stack Overflow (https:\/\/stackoverflow.com\/q\/20083932\/98509) in relation to the correct usage of `startkey_docid`. The question was prompted as the user was passing in a valid `startkey` and `startkey_docid`, however the `startkey_docid` appeared to [&hellip;]","og_url":"https:\/\/www.couchbase.com\/blog\/startkeydocid-behaviour\/","og_site_name":"The Couchbase Blog","article_published_time":"2014-12-16T18:04:45+00:00","article_modified_time":"2023-06-28T08:19:02+00:00","author":"Brett Lawson, Principal Software Engineer, Couchbase","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Brett Lawson, Principal Software Engineer, Couchbase","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.couchbase.com\/blog\/startkeydocid-behaviour\/#article","isPartOf":{"@id":"https:\/\/www.couchbase.com\/blog\/startkeydocid-behaviour\/"},"author":{"name":"Brett Lawson, Principal Software Engineer, Couchbase","@id":"https:\/\/www.couchbase.com\/blog\/#\/schema\/person\/5cfc2fbf25776be2a027a474562be02f"},"headline":"`startkey_docid` Behaviour","datePublished":"2014-12-16T18:04:45+00:00","dateModified":"2023-06-28T08:19:02+00:00","mainEntityOfPage":{"@id":"https:\/\/www.couchbase.com\/blog\/startkeydocid-behaviour\/"},"wordCount":279,"commentCount":4,"publisher":{"@id":"https:\/\/www.couchbase.com\/blog\/#organization"},"image":{"@id":"https:\/\/www.couchbase.com\/blog\/startkeydocid-behaviour\/#primaryimage"},"thumbnailUrl":"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2022\/11\/couchbase-nosql-dbaas.png","inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.couchbase.com\/blog\/startkeydocid-behaviour\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.couchbase.com\/blog\/startkeydocid-behaviour\/","url":"https:\/\/www.couchbase.com\/blog\/startkeydocid-behaviour\/","name":"`startkey_docid` Behaviour - The Couchbase Blog","isPartOf":{"@id":"https:\/\/www.couchbase.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.couchbase.com\/blog\/startkeydocid-behaviour\/#primaryimage"},"image":{"@id":"https:\/\/www.couchbase.com\/blog\/startkeydocid-behaviour\/#primaryimage"},"thumbnailUrl":"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2022\/11\/couchbase-nosql-dbaas.png","datePublished":"2014-12-16T18:04:45+00:00","dateModified":"2023-06-28T08:19:02+00:00","breadcrumb":{"@id":"https:\/\/www.couchbase.com\/blog\/startkeydocid-behaviour\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.couchbase.com\/blog\/startkeydocid-behaviour\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.couchbase.com\/blog\/startkeydocid-behaviour\/#primaryimage","url":"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2022\/11\/couchbase-nosql-dbaas.png","contentUrl":"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2022\/11\/couchbase-nosql-dbaas.png","width":1800,"height":630},{"@type":"BreadcrumbList","@id":"https:\/\/www.couchbase.com\/blog\/startkeydocid-behaviour\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.couchbase.com\/blog\/"},{"@type":"ListItem","position":2,"name":"`startkey_docid` Behaviour"}]},{"@type":"WebSite","@id":"https:\/\/www.couchbase.com\/blog\/#website","url":"https:\/\/www.couchbase.com\/blog\/","name":"The Couchbase Blog","description":"Couchbase, the NoSQL Database","publisher":{"@id":"https:\/\/www.couchbase.com\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.couchbase.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.couchbase.com\/blog\/#organization","name":"The Couchbase Blog","url":"https:\/\/www.couchbase.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.couchbase.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/2023\/04\/admin-logo.png","contentUrl":"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/2023\/04\/admin-logo.png","width":218,"height":34,"caption":"The Couchbase Blog"},"image":{"@id":"https:\/\/www.couchbase.com\/blog\/#\/schema\/logo\/image\/"}},{"@type":"Person","@id":"https:\/\/www.couchbase.com\/blog\/#\/schema\/person\/5cfc2fbf25776be2a027a474562be02f","name":"Brett Lawson, Principal Software Engineer, Couchbase","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.couchbase.com\/blog\/#\/schema\/person\/image\/ee3586f0c112c20e863af447d44dec8f","url":"https:\/\/secure.gravatar.com\/avatar\/6aec1ba24ef7558a248dcde7b7a18b15b06e2885b24b663906a448634066c1c4?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/6aec1ba24ef7558a248dcde7b7a18b15b06e2885b24b663906a448634066c1c4?s=96&d=mm&r=g","caption":"Brett Lawson, Principal Software Engineer, Couchbase"},"description":"Brett Lawson is a Principal Software Engineer at Couchbase. Brett is responsible for the design and development of the Couchbase Node.js and PHP clients as well as playing a role in the design and development of the C library, libcouchbase.","url":"https:\/\/www.couchbase.com\/blog\/author\/brett-lawson\/"}]}},"authors":[{"term_id":9004,"user_id":31,"is_guest":0,"slug":"brett-lawson","display_name":"Brett Lawson, Principal Software Engineer, Couchbase","avatar_url":"https:\/\/secure.gravatar.com\/avatar\/6aec1ba24ef7558a248dcde7b7a18b15b06e2885b24b663906a448634066c1c4?s=96&d=mm&r=g","author_category":"","last_name":"Lawson","first_name":"Brett","job_title":"","user_url":"","description":"Brett Lawson is a Principal Software Engineer at Couchbase. Brett is responsible for the design and development of the Couchbase Node.js and PHP clients as well as playing a role in the design and development of the C library, libcouchbase."}],"_links":{"self":[{"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/posts\/1797","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/users\/31"}],"replies":[{"embeddable":true,"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/comments?post=1797"}],"version-history":[{"count":0,"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/posts\/1797\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/media\/13873"}],"wp:attachment":[{"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/media?parent=1797"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/categories?post=1797"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/tags?post=1797"},{"taxonomy":"author","embeddable":true,"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/ppma_author?post=1797"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}