couchdb-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Luke Bredeson <luke.brede...@gmail.com>
Subject Re: Erlang view question
Date Sun, 20 Nov 2011 18:28:26 GMT
That did the trick; I recreated the view with list_to_binary and things are
now as expected.  Thanks for the help!

Luke

On Sun, Nov 20, 2011 at 12:05 PM, Paul Davis <paul.joseph.davis@gmail.com>wrote:

> 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
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message