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,{[]}),
to:
{Price} = couch_util:get_value(<<"price">>, Doc, {[]}),
And this:
> MyDoc = [{"item_id", DocId}, {"store_id", Store},{"price_count",PriceCount}],
to:
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
encoders.
HTH,
Paul Davis
> Encoded = mochijson2:encode({struct, MyDoc}),
> {[{<<"code">>, 200}, {<<"headers">>, {[{<<"Content-Type">>,
> <<"text/plain">>}]}}, {<<"body">>, Encoded}]}
> end.
>