couchdb-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Paul Davis <paul.joseph.da...@gmail.com>
Subject Re: Erlang view question
Date Sun, 20 Nov 2011 18:05:16 GMT
Quite correct. This map function is emitting "2008" vs <<"2008">>.
Change to fix it should be:

Emit([couch_util:get_value(<<"city">>, Doc), list_to_binary(Year)], 1);

On Sun, Nov 20, 2011 at 12:00 PM, Jens Alfke <jens@couchbase.com> wrote:
> 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