tags:

views:

59

answers:

2

As many of you will know the response from a couchdb view is as follows

{"rows":[
  {"key":"1","value":{"Col1":"Some Value"}},
  {"key":"2","value":{"Col1":"Another Value"}},
]}

Well I would like to collate that to

[{"key":"1","value":{"Col1":"Some Value"}},
  {"key":"2","value":{"Col1":"Another Value"}}]

I am considering using a "List Function" to collate the response but I wanted to know the potential performance overhead of doing something like this?? Is it worth it... or should I consider changing all my code to handle the different response??

Thanks Damo

+1  A: 

A list function runs in a separate process (couchjs) which is connected to couchdb via standard i/o. Data is serialized to/from JSON to communicate with this channel. In other words, all of your rows will be serialized and sent to couchjs; and couchjs will send the results back.

Therefore, a list function will add (at least) an O(n) latency to receive your results. For small (I say less than 10,000 documents but it depends on your needs) view results, it is well worth the convenience. For very large amounts of rows, you may find benefit in upgrading your clients.

jhs
As I thought then. Not ideal as sometimes you'll be passing a "document" and others a "view of a document". So your code needs to handle both. I decided to use a list function in the end to push all values to an array and then send the JSOn respone. Thanks for your help.
dworrad
List functions can use `provides()` to return different content types, perhaps based on a parameter given in the `req.query` object.
jhs
A: 

I use JSON_XS to format the result, then curl, awk and other unix utilities to reformat the result. In this case pretty-printing the JSON doesn't help so:

curl -s -S --compressed -X GET 'your_view_url' | sed -e '/^{"rows"://' -e '/^]}/]/'

duomark