incubator-couchdb-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Stefan Kögl <koeglste...@gmail.com>
Subject Re: tinkering with limits while replicating
Date Tue, 05 Feb 2013 20:06:39 GMT
On Tue, Feb 5, 2013 at 8:06 PM, Tibor Gemes <tibber@gmail.com> wrote:

> A simle example which filters by type:
>
> fun({Doc}, {Req}) ->
>         DocType = couch_util:get_value(<<"type">>, Doc),
>         case DocType of
>                 undefined -> false;
>                 <<"mytype">> ->       true;
>                 _ -> false
>         end
> end.
>
>
> This is another example. A bit more complicated. This receives a values
> query parameter (comma separated). The filter lets through any design docs,
> any _deleted docs, and the mytype doc only if its value propery is
> contained in the query parameter:
>
> fun({Doc}, {Req}) ->
>         DocId = couch_util:get_value(<<"_id">>, Doc),
>         DocType = couch_util:get_value(<<"type">>, Doc),
>         DocValue = couch_util:get_value(<<"value">>, Doc),
>         DocDeleted = couch_util:get_value(<<"_deleted">>, Doc),
>
>         {Query} = couch_util:get_value(<<"query">>,Req, {[]}),
>         ValuesParam = couch_util:get_value(<<"values">>,Query),
>         Values = binary:split(ValuesParam, <<",">>, [global]),
>         case {DocId, DocDeleted}  of
>         {<<"_design/", _/binary>>, _} -> true;
>         {_, true} -> true;
>         _ ->
>                 case DocType of
>                         undefined -> false;
>                         <<"mytype">> -> lists:any(fun(E) -> E =:= DocValue
> end, Values);
>                         _ -> false
>                 end
>         end
> end.
>
> Those might be suboptimal but works perfectly for me.
>

Thanks for sharing. I've added them as examples to the wiki with links to
your mail

 http://wiki.apache.org/couchdb/EnableErlangViews

-- Stefan

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message