[Views] startkey_docid doesn't work except for _all_docs

Hello,

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 :

curl http://127.0.0.1:8091/couchBase/default/_all_docs
{"total_rows":3,"rows":[
{"id":"key1","key":"key1","value":{"rev":"1-0008e9b571d0e8d10000000000000000"}},
{"id":"key2","key":"key2","value":{"rev":"1-0008e9b845ed09e20000000000000000"}},
{"id":"key3","key":"key3","value":{"rev":"1-0008e9ba1da51ce60000000000000000"}}
]
{}

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

curl http://127.0.0.1:8091/couchBase/default/_all_docs?startkey_docid=key2
{"total_rows":3,"rows":[
{"id":"key2","key":"key2","value":{"rev":"1-0008e9b845ed09e20000000000000000"}},
{"id":"key3","key":"key3","value":{"rev":"1-0008e9ba1da51ce60000000000000000"}}
]
}

- 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 'http://127.0.0.1:8092/default/_design/dev_myView/_view/myAll_docs'

{"total_rows":3,"rows":[
{"id":"key1","key":"key1","value":{"rev":"1-0008e9b571d0e8d10000000000000000"}},
{"id":"key2","key":"key2","value":{"rev":"1-0008e9b845ed09e20000000000000000"}},
{"id":"key3","key":"key3","value":{"rev":"1-0008e9ba1da51ce60000000000000000"}}
]
}

- Query this view with startkey_docid = key2 : startkey_docid doesn't work as expected

curl 'http://127.0.0.1:8092/default/_design/dev_myView/_view/myAll_docs?startk...'

{"total_rows":3,"rows":[
{"id":"key1","key":"key1","value":{"rev":"1-0008e9b571d0e8d10000000000000000"}},
{"id":"key2","key":"key2","value":{"rev":"1-0008e9b845ed09e20000000000000000"}},
{"id":"key3","key":"key3","value":{"rev":"1-0008e9ba1da51ce60000000000000000"}}
]
}

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)

Regards,

Xavier

1 Answer

« Back to question.

Hello,

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:
http://blog.couchbase.com/pagination-couchbase

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

Regards
Tug
@tgrall