benoitc / couchbeam

Apache CouchDB client in Erlang
Other
242 stars 114 forks source link

startkey, endkey parameters aren't working #64

Closed denisok closed 12 years ago

denisok commented 12 years ago

query: Options = [{startkey, [Date, list_to_bitstring(Branch)]}, {endkey, [Date, list_to_bitstring(Branch), {[]}]}], DesignName = "vetting", ViewName = "tests_groups", {ok, _ViewResults} = couchbeam_view:fetch(Db, {DesignName, ViewName}, Options).

Isn't working correctly.

That is because couchbeam_view.erl parsing startkey/endkeys atoms as: parse_view_options([{start_key, Value}|Rest], #view_query_args{options=Opts}=Args) -> Opts1 = [{"start_key", Value}|Opts], parse_view_options(Rest, Args#view_query_args{options=Opts1}); parse_view_options([{end_key, Value}|Rest], #view_query_args{options=Opts}=Args) -> Opts1 = [{"end_key", Value}|Opts],

but according to http://wiki.apache.org/couchdb/HTTP_view_API, this parameters should be named as "startkey" and "endkey".

denisok commented 12 years ago

CouchDB 1.1.1 was used to reproduce

benoitc commented 12 years ago

Both should be handled : https://github.com/apache/couchdb/blob/1.1.x/src/couchdb/couch_httpd_view.erl#L305

What is the error on couchdb side ?

denisok commented 12 years ago

no error at least in /usr/local/var/log/couchdb/couch.log. view just return all documents, seems just ignoring query.

I am using MacBook Pro, and installed couch with help of brew

benoitc commented 12 years ago

Can you define what isn't working and such. So far tests pass here.

yfyf commented 12 years ago

This is probably related to this: https://issues.apache.org/jira/browse/COUCHDB-949 You are probably using an old version of CouchDB, since CouchBeam uses the new "start_key" syntax.

benoitc commented 12 years ago

1.1.1 is supposed to have the support for these commands. I'm not sure what could be the problem here, Also I don't reproduce it.

denisok commented 12 years ago

I would like to help. Will try to find sources that brew is using to install couchdb. What else I could do to find what is the issue? Doc on wiki are confusing, that declares only startkey.

denisok commented 12 years ago

So I think issue is: I was confused by http://wiki.apache.org/couchdb/HTTP_view_API and used atom startkey instead of start_key for couchbeam. So couchbeam couldn't parse that atom.

But using atom start_key give me next exception: \ exception error: bad argument in function mochiweb_util:quote_plus/2 in call from mochiweb_util:'-urlencode/1-fun-0-'/2 in call from lists:foldr/3 in call from mochiweb_util:urlencode/1 in call from couchbeam:make_url/3 in call from couchbeam_view:make_view/4 in call from couchbeam_view:fetch/3 in call from if_couchdb:get_tests_groups/2

will try to figure out what is that.

denisok commented 12 years ago

tried to run mociweb_util:urlencode in erl shell with parameter: [{"start_key",[1324932287,<<"8a6a105b63b5e2d0">>]}]

give same exception. And this seems related to parameters that I pass to start_key.

denisok commented 12 years ago

same issue when I am not using atom, but passing "start_key": Options = [{"startkey", [Date, list_to_bitstring(Branch)]}, {"endkey", [Date, list_to_bitstring(Branch), {[]}]} ] Strange, because when I am passing "startkey" - everything works fine.

make_url:[{"end_key",[1324932287,<<"8a6a105b63b5e2d0">>,{[]}]}, {"start_key",[1324932287,<<"8a6a105b63b5e2d0">>]}] new:[{"start_key",[1324932287,<<"8a6a105b63b5e2d0">>]}, {"end_key",[1324932287,<<"8a6a105b63b5e2d0">>,{[]}]}] \ exception error: bad argument in function mochiweb_util:quote_plus/2 in call from mochiweb_util:'-urlencode/1-fun-0-'/2 in call from lists:foldr/3 in call from mochiweb_util:urlencode/1 in call from couchbeam:make_url/3 in call from couchbeam_view:make_view/4 in call from couchbeam_view:fetch/3 in call from if_couchdb:get_tests_groups/2

But using atom start_key - everything OK now ) Thanks.

benoitc commented 12 years ago

passing atoms is the way to do anyway. Thanks for the feedback :)