incubator-couchdb-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Dave Cottlehuber <...@jsonified.com>
Subject Re: {case_clause,{error,[],function_clause}} in CouchDb-1.2.0
Date Thu, 27 Jun 2013 14:54:34 GMT
On 27 June 2013 16:38, Alexander Kuleshov <akuleshov@tpip.net> wrote:
> Hello,
>
> I'm trying to use Couchdb-1.2.0 with Couchbeam.
>
> I create database, documents and etc...
>
> I have a view:
>
> {
>    "_id": "_design/task",
>    "_rev": "1-0ba3c64c158deb66749cf23aaee9e855",
>    "language": "erlang",
>    "views": {
>        "by_task_creation": {
>            "map": "fun({Doc}) ->\n\tcase couch_util:get_value(<<\"_id\">>,
Doc, null) of\n\t    TaskId = <<\"task:\", _/binary>> ->\n\t\tcase couch_util:get_value(<<\"created\">>,
Doc, null) of\n\t\t    null -> ok;\n\t\t    Created -> Emit(Created, null)\n\t\tend;\n\t
   _ -> ok\n\tend\nend.\n",
>            "reduce": "fun(_Keys, Values, false) -> length(Values);\n   (_Keys, Values,
true)  -> lists:sum(Values) end.\n"
>        },
>        "by_task_selector": {
>            "map": "fun({Doc}) ->\n\tcase couch_util:get_value(<<\"_id\">>,
Doc, null) of\n\t    TaskId = <<\"task:\", _/binary>> ->\n\t\tcase couch_util:get_value(<<\"selector\">>,
Doc, null) of\n\t\t    null -> ok;\n\t\t    Selector -> Emit(Selector, TaskId)\n\t\tend;\n\t
   _ -> ok\n\tend\nend.\n"
>        }
>    }
> }
>
> But when i'm trying to fetch it i got error:
>
> {case_clause,{error,[],function_clause}}
>
> I'm trying with: couchbeam_view:fetch(DB, {<<"_design/task">>, <<"by_task_creation">>},
[{reduce, true}])
>
> How can i make it correctly?
>
> Thank you.

case_clause is a runtime error telling you that your erlang function
doesn't match all cases encountered.  Add a default case in and you
should be fine. I'm not trying to decipher the
\n\t\tunread\table\n\t\tcontent above but if you start couchdb in
interactive mode `couchdb -i` then you can test stuff in the shell
very easily:

where you'll need to update the "…" stuff obviously.

rr("/repos/couch/git/src/couchdb/*.hrl").
rr("/repos/couch/git/src/couch_mrview/include/*.hrl").
{ok, Db} = couch_db:open_int(<<"somedb">>, []).
{ok, Doc} = couch_db:open_doc(Db, <<"somedocid">>).
Body = couch_doc:with_ejson_body(Doc). may also be useful.

and then call your fun on these docs to see what's happening.

If you `couch_config:set("log","level","debug").` prior to triggering
a view rebuild, you will probably see what doc this is failing on in
the logs. Most commonly people forget that databases contain ddocs and
don't account for that in the view.

A+
Dave

Mime
View raw message