[Views] startkey_docid doesn't work except for _all_docs


The startkey_docid view parameter doesn’t seam to have any effect on views.
It only works with the “undocumented/unsupported” _all_docs view each time we test it

Example :

  • Create the default bucket on a fresh couchbase cluster/server

  • Insert 3 keys : key1, key2, key3 (any value is fine)

  • Query the _all_docs view with no startkey_docid :

  • Query the _all_docs view with startkey_docid = key2 : startkey_docid works as expected

  • Create a custom view that mimics the all _all_docs view (simple Map, no Reduce) :

            function (doc, meta) {
              emit(meta.id, {"rev": meta.rev});
  • Query this custom view with no startkey_docid :

            curl ''
  • Query this view with startkey_docid = key2 : startkey_docid doesn’t work as expected

            curl ''

Are we missing something with the way it should work ?
The Doc states it is much efficient to use startkey_docid rather than startkey (and we are sure it is), but what is the proper way to use it on custom views ?

We have tested it on different couchbase cluster, on different platforms (centOS, uBuntu, OSX), with different custom views, including reduce or not, and it never gives the expected output.

We are currently running on v2.1.1 CE (we think we tried it with every couchbase CE version since 2.0 with the same behaviour)




I am under the impression you are mixing the startkey/endkey parameters that are used to deal with range queries, with the startkey_docid/endkey_docid that are used for pagination.

I am inviting you to look at this blog post:

Let me know if you have more questions, and I will also ensure we clarify the documentation.


Ok, thank you : it seams we just didn’t read this part of the doc :

When using startkey_docid you must specify the startkey parameter to specify the information being searched for.

We thought we could use startkey_docid the same way as the _all_docs view <- with no startkey

By the way, The use of the startkey_docid returns output that is pretty much unpredictable when you want to use it for something that is not “pagination related”; Ex :

Imagine you have the following items in your bucket :

key value
key1 {“groupKey”:“groupA”}
key2 {“groupKey”:“groupA”}
key3 {“groupKey”:“groupA”}
key4 {“groupKey”:“groupB”}
key5 {“groupKey”:“groupB”}
key6 {“groupKey”:“groupB”}
key7 {“groupKey”:“groupC”}
key8 {“groupKey”:“groupC”}
key9 {“groupKey”:“groupC”}

with the view :

function (doc, meta) {
emit(doc.groupKey, null);

The following view call is pretty much unexpected :



The doc states : “startkey_docid Return records starting with the specified document ID”

startkey_docid was set to key7, but the view output starts at key4 (??)


Can somebody of Couchbase give Xavier an explanation?
We are also trying to understand the use of startkey_docid parameter for pagination and we encounter the same issues!

We have a simple view:

function (doc, meta) {
if (doc.doc_type && doc.doc_type == ‘circle’) {


The result is as expected = 130 rows, extract:


now if we add the id of the 4th row as the startkey_docid, should the result not start at the 4th row??


The result is still the same 130 rows starting with the 1st row??

We thought maybe that startkey_docid parameter can only be used combined with a startkey so we run following url:


Not better?

We are using
Version: 2.2.0 community edition (build-837)

Your help will be appreciated



I found my problem here:

To use startkey_docid you need to supply a startkey and DO NOT SURROUND your doc id with "
so this worked for me:

And to be more precise/complete: startkey_docid must be used together with the startkey which is the key of the index of the row with doc id = startkey_docid.

More info here:
see http://blog.couchbase.com/startkeydocid-behaviour