benoitc / couchbeam

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

couchbeam_view:fetch/3 with 'keys' option seems to not work #117

Closed nlfiedler closed 9 years ago

nlfiedler commented 9 years ago

I have tried a number of variations and none produce any results. Meanwhile, a simple Python script to make the HTTP request works as expected. I was hoping the 005_view.t test would offer an example, but it does not. Below is my test code:

Tags = ["cat", "picnic"], BinTags = [list_to_binary(Tag) || Tag <- Tags], Options = [{keys, BinTags}], {ok, Rows} = couchbeam_view:fetch(Db, {"assets", "by_tag"}, Options),

The Rows collection is always empty, no matter what variations I try with the tags conversion.

In the CouchDB log I always see this:

127.0.0.1 - - GET /tanuki_test/_design/assets/_view/by_tag?key=%22catpicnic%22 200

That does not seem right. My Python test uses the correct POST request with a JSON encoded body. From what I can tell, the couchbeam_view code should as well, but apparently something is not working as expected. If there is something I am doing wrong, please let me know. Thanks.

benoitc commented 9 years ago

Hrm, I don't reproduce it on the latest version of couchbeam:

1> couchbeam:start().
ok
2> S = couchbeam:server_connection(<<"http://admin:rm@127.0.0.1:5984">>).
{server,<<"http://admin:rm@127.0.0.1:5984">>,
        [{connect_options,[{nodelay,true}]}]}
3> {ok, Db} = couchbeam:open_db(S, <<"testdb1">>).
{ok,{db,{server,<<"http://admin:rm@127.0.0.1:5984">>,
                [{connect_options,[{nodelay,true}]}]},
        <<"testdb1">>,
        [{connect_options,[{nodelay,true}]}]}}
4> couchbeam_view:all(Db).
{ok,[{[{<<"id">>,<<"7adecc31d3a4aca4cf44ecc2fd00036b">>},
       {<<"key">>,<<"7adecc31d3a4aca4cf44ecc2fd00036b">>},
       {<<"value">>,
        {[{<<"rev">>,<<"1-239314fd1ff718df51b10e25964552f9">>}]}}]},
     {[{<<"id">>,<<"7adecc31d3a4aca4cf44ecc2fd001129">>},
       {<<"key">>,<<"7adecc31d3a4aca4cf44ecc2fd001129">>},
       {<<"value">>,
        {[{<<"rev">>,<<"1-d7b10f610a3b9476ac686e4a85397e49">>}]}}]},
     {[{<<"id">>,<<"7adecc31d3a4aca4cf44ecc2fd0015fa">>},
       {<<"key">>,<<"7adecc31d3a4aca4cf44ecc2fd0015fa">>},
       {<<"value">>,
        {[{<<"rev">>,<<"1-55b4ed79b745529b00dbc17aefee4b9a">>}]}}]},
     {[{<<"id">>,<<"7adecc31d3a4aca4cf44ecc2fd0023b8">>},
       {<<"key">>,<<"7adecc31d3a4aca4cf44ecc2fd0023b8">>},
       {<<"value">>,
        {[{<<"rev">>,<<"1-904ac758cd75bd7fb07870ae3c09064e">>}]}}]},
     {[{<<"id">>,<<"_design/test">>},
       {<<"key">>,<<"_design/test">>},
       {<<"value">>,
        {[{<<"rev">>,
           <<"1-9ca99d2977400651772f5553bebea96a">>}]}}]}]}
5> Keys = [<<"a">>, <<"b">>].
[<<"a">>,<<"b">>]
6> couchbeam_view:fetch(Db, {<<"test">>, <<"test">>}, [{keys, Keys}]).
{ok,[{[{<<"id">>,<<"7adecc31d3a4aca4cf44ecc2fd00036b">>},
       {<<"key">>,<<"a">>},
       {<<"value">>,
        {[{<<"_id">>,<<"7adecc31d3a4aca4cf44ecc2fd00036b">>},
          {<<"_rev">>,<<"1-239314fd1ff718df51b10e25964552f9">>},
          {<<"test">>,<<"a">>}]}}]},
     {[{<<"id">>,<<"7adecc31d3a4aca4cf44ecc2fd001129">>},
       {<<"key">>,<<"b">>},
       {<<"value">>,
        {[{<<"_id">>,<<"7adecc31d3a4aca4cf44ecc2fd001129">>},
          {<<"_rev">>,<<"1-d7b10f610a3b9476ac686e4a85397e49">>},
          {<<"test">>,<<"b">>}]}}]}]}

Which version of couchdb are you using?

nlfiedler commented 9 years ago

Oh dear, I found my mistake. I was missing an 's' in my test code and was calling the wrong function. That explains a number of things, including why my logging messages were not rendered. Sorry for the trouble. Couchbeam is terrific, by the way.