couchdb-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Paul Davis <>
Subject Re: Building a JSON Show in Erlang
Date Tue, 04 Oct 2011 03:18:48 GMT
Assuming you want the keys from price to be at the same level as item_id:

Change this:

> Price = couch_util:get_value(<<"price">>, Doc,{[]}),


{Price} = couch_util:get_value(<<"price">>, Doc, {[]}),

And this:

> MyDoc = [{"item_id", DocId}, {"store_id", Store},{"price_count",PriceCount}],


MyDoc = [{"item_id", DocId, {"store_id", Store}, {"price_count",
PriceCount}] ++ Price,

Also, its been awhile, but if memory serves, if you return the body as
{<<"json">>, {MyDoc}} CouchDB will automatically ?JSON_ENCODE that
into a string. This is good because if you're using newer Couches,
you'll automatically get the speed improvements from using the C based

Paul Davis

> Encoded = mochijson2:encode({struct, MyDoc}),
> {[{<<"code">>, 200}, {<<"headers">>, {[{<<"Content-Type">>,
> <<"text/plain">>}]}}, {<<"body">>, Encoded}]}
> end.

View raw message