couchdb-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jens Alfke <j...@couchbase.com>
Subject Re: Erlang view question
Date Sun, 20 Nov 2011 18:00:24 GMT
I'm pretty sure that you need to return all strings as binary objects, as that's the way Erlang's
JSON mapping tells the difference between arrays and strings.

--Jens

On Nov 20, 2011, at 9:38 AM, "Luke Bredeson" <luke.bredeson@gmail.com> wrote:

> Hi,
> 
> I have an Erlang view that is outputting a list of integers instead of a
> string.  I know Erlang treats strings as lists of integers, but I thought
> CouchDB would take care of this for me.  I'm sure it's a basic error on my
> part, so if anyone has any ideas of what I'm doing wrong, I'd appreciate
> it!  Here's the relevant map function:
> 
>      fun({Doc}) ->
>        case couch_util:get_value(<<"type">>, Doc) of
>          <<"Crash">> ->
>            Accdate = couch_util:get_value(<<"accdate">>, Doc),
>            Year = string:substr(erlang:bitstring_to_list(Accdate), 7, 4),
>            Emit([couch_util:get_value(<<"city">>, Doc), Year], 1);
>          _ ->
>            ok
>        end
>      end.
> 
> I get values like:  ["3425", [50, 48, 48, 56]], when I'm really looking for
> values like this:  ["3425", "2008"].
> 
> Thanks,
> Luke

Mime
View raw message