Hi I'm looking to extend our usage of couchdb by replacing our mysql reporting db. Whilst using couchdb successfully for a number of varied use cases I've never had to do much with reduce so I'm unsure on how to use it to reduce an array of values.
Basically I want to be able to search a database using a composite key and retrieving some aggregated information about number of calls, call status, avg time to answer and avg duration The following view shows how I'd like it to work: Key = <Application, Account, Subscription> Value = <1, answered, busy, noreply, time to answer, duration> e.g. ["NTS", "NetDev", "MySub1"], [1,1,0,0,100,200] ["NTS", "NetDev", "MySub1"], [1,1,0,0,150,400] ["NTS", "NetDev", "MySub1"], [1,1,0,0,170,500] ["NTS", "NetDev", "MySub1"], [1,0,1,0,0,0] ["NTS", "NetDev", "MySub1"], [1,0,1,0,0,0] ["NTS", "NetDev", "MySub1"], [1,0,0,2,0,0] ["NTS", "NetDev", "MySub1"], [1,0,0,2,0,0] My Reduced output should look like this: [7,3,2,2,420,1100] i.e. 7 calls in total, 3 answered, 2 busy, 2 no reply, the total time for time to answer is 420 and the total time for call duration is 1100. I can then compute the two averages after getting the data back from couch i.e. 420/no. of answered calls(3) and 1100/no. of answered calls(3) I thought that sum(values) would do this for me but it just upsets couch: Reduce output must shrink more rapidly: Current output: '["001,11,11,11,11,11,11,11,11,11,11,101,11,11,11,11,11,11,11,11,11,11,11,101,11,11,11,11,11,11,11,11'... (first 100 of 277 bytes) What should my reduce function look like? Thanks John
