You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@couchdb.apache.org by Pablo Sortino <ps...@gmail.com> on 2008/11/25 14:58:51 UTC

Is CouchDB allowing the use of "startkey_docid" parameter in views?

A view with startkey_docid is not working.
It is working if I use _all_docs.

For the following database named "psortino" with a view (username):

The "username" view is: function(doc) { emit(doc.username, null) }

1) http://localhost:5984/psortino/_all_docs
{"total_rows":6,"offset":0,"rows":[
{"id":"048cdb8d0971e625e86730ffc10eda0d","key":"048cdb8d0971e625e86730ffc10eda0d","value":{"rev":"2554919371"}},
{"id":"056492cd6da7f36a967fdcd58d749850","key":"056492cd6da7f36a967fdcd58d749850","value":{"rev":"3482973537"}},
{"id":"_design/foo","key":"_design/foo","value":{"rev":"192023970"}},
{"id":"a8b7bff9d9cdc66a9799d97941f9e1d3","key":"a8b7bff9d9cdc66a9799d97941f9e1d3","value":{"rev":"998738065"}},
{"id":"ef20ce5f076d05c567535f9ae3835a43","key":"ef20ce5f076d05c567535f9ae3835a43","value":{"rev":"2828544738"}},
{"id":"ff51c5fa2c4f2b6ad2859d28d0017ae3","key":"ff51c5fa2c4f2b6ad2859d28d0017ae3","value":{"rev":"242782642"}}
]}


2) http://localhost:5984/psortino/_view/foo/username
{"total_rows":5,"offset":0,"rows":[
{"id":"056492cd6da7f36a967fdcd58d749850","key":"mdixon","value":null},
{"id":"ef20ce5f076d05c567535f9ae3835a43","key":"mdixon","value":null},
{"id":"ff51c5fa2c4f2b6ad2859d28d0017ae3","key":"mdixon","value":null},
{"id":"048cdb8d0971e625e86730ffc10eda0d","key":"nsantos","value":null},
{"id":"a8b7bff9d9cdc66a9799d97941f9e1d3","key":"sbristow","value":null}
]}


3)
http://localhost:5984/psortino/_all_docs?startkey_docid=a8b7bff9d9cdc66a9799d97941f9e1d3
{"total_rows":6,"offset":3,"rows":[
{"id":"a8b7bff9d9cdc66a9799d97941f9e1d3","key":"a8b7bff9d9cdc66a9799d97941f9e1d3","value":{"rev":"998738065"}},
{"id":"ef20ce5f076d05c567535f9ae3835a43","key":"ef20ce5f076d05c567535f9ae3835a43","value":{"rev":"2828544738"}},
{"id":"ff51c5fa2c4f2b6ad2859d28d0017ae3","key":"ff51c5fa2c4f2b6ad2859d28d0017ae3","value":{"rev":"242782642"}}
]}


4)
http://localhost:5984/psortino/_view/foo/username?startkey_docid=048cdb8d0971e625e86730ffc10eda0d
{"total_rows":5,"offset":0,"rows":[
{"id":"056492cd6da7f36a967fdcd58d749850","key":"mdixon","value":null},
{"id":"ef20ce5f076d05c567535f9ae3835a43","key":"mdixon","value":null},
{"id":"ff51c5fa2c4f2b6ad2859d28d0017ae3","key":"mdixon","value":null},
{"id":"048cdb8d0971e625e86730ffc10eda0d","key":"nsantos","value":null},
{"id":"a8b7bff9d9cdc66a9799d97941f9e1d3","key":"sbristow","value":null}
]}

--- Here ---> 4) should returns
[{"id":"048cdb8d0971e625e86730ffc10eda0d","key":"nsantos","value":null},
{"id":"a8b7bff9d9cdc66a9799d97941f9e1d3","key":"sbristow","value":null}]

Is this a bug? or we can't use startkey_docid with views?
Is there something wrong on my url?

The same happens for "endkey_docid" parameter.
I found the same issue on versions 0.8 and 0.9


Thanks in advance.
Pablo.

Re: Is CouchDB allowing the use of "startkey_docid" parameter in views?

Posted by Pablo Sortino <ps...@gmail.com>.
Thanks a lot.

If someone has the same issue I fixed the url by adding "startkey".

http://localhost:5984/psortino/_view/foo/username?startkey=
"nsantos"&startkey_docid=048cdb8d0971e625e86730ffc10eda0d

BTW: Good explanation.

Pablo.


On Tue, Nov 25, 2008 at 2:37 PM, Chris Anderson <jc...@apache.org> wrote:

> On Tue, Nov 25, 2008 at 5:58 AM, Pablo Sortino <ps...@gmail.com> wrote:
> > A view with startkey_docid is not working.
>
> startkey_docid is only meant as a method to make finer distinctions
> than startkey alone can make. That is, it should have no effect unless
> you have rows in your view with the same key, and have specified a
> startkey.
>
> When you have, say, many many docs all with the same date, so that
> startkey and endkey alone would not be sufficient to give a small
> range of them, the startkey_docid and endkey_docid can be used to
> specify a sub range of rows which all have the same key.
>
> The view storage engine stores the rows under the meta-key: {key,
> docid} so queries usually just ignore the docid, but when a startkey
> as well as a startkey_docid are both specified, then the comparison
> includes the docid part of the meta-key as well.
>
> ...maybe not my clearest explanation ever, but I hope it helps.
>
>
> --
> Chris Anderson
> http://jchris.mfdz.com
>

Re: Is CouchDB allowing the use of "startkey_docid" parameter in views?

Posted by Chris Anderson <jc...@apache.org>.
On Tue, Nov 25, 2008 at 5:58 AM, Pablo Sortino <ps...@gmail.com> wrote:
> A view with startkey_docid is not working.

startkey_docid is only meant as a method to make finer distinctions
than startkey alone can make. That is, it should have no effect unless
you have rows in your view with the same key, and have specified a
startkey.

When you have, say, many many docs all with the same date, so that
startkey and endkey alone would not be sufficient to give a small
range of them, the startkey_docid and endkey_docid can be used to
specify a sub range of rows which all have the same key.

The view storage engine stores the rows under the meta-key: {key,
docid} so queries usually just ignore the docid, but when a startkey
as well as a startkey_docid are both specified, then the comparison
includes the docid part of the meta-key as well.

...maybe not my clearest explanation ever, but I hope it helps.


-- 
Chris Anderson
http://jchris.mfdz.com