Hi Mike, Do, for one of the views, I need to return an average.
So, my reduce function had - "cpu": { "map": "function(doc) { if ((doc.type == 'performance_stats')) emit(doc.test_id, doc.CPU) }", "reduce": "function(keys, values) " "{ " "avg = Math.round(sum(values)/values.length);" "return(avg)" " }" Now, if I want to use stats, which give me sum and count, I tried this, but doesn't work. What am I doing wrong? "cpu": { "map": "function(doc) { if ((doc.type == 'performance_stats')) emit(doc.test_id, doc.CPU) }", "reduce": "function(keys, values) " "{ " "avg = Math.round(_sum/_count);" "return(avg)" " }" -Radhika -----Original Message----- From: Mike Marino [mailto:mmar...@gmail.com] Sent: Wednesday, May 21, 2014 10:32 AM To: user@couchdb.apache.org Subject: Re: running views return nothing with couchdb1.5.1 Hi Radhika, What does the server status say in futon? (i.e. does it note that the views are building or not?) One side comment, the reduce functions that you posted will likely not do what you expect when a rereduce is run. I would suggest using _stats (preferable solution, http://couchdb.readthedocs.org/en/latest/couchapp/ddocs.html#builtin-reduce-functions ). Cheers, Mike On Wed, May 21, 2014 at 4:25 PM, Ramanadham, Radhika < radhika.ramanad...@emc.com> wrote: > Hi, > > I have some code that creates DB, documents and design documents with > views and lists. > > When I run views, I don't know why, but it returns nothing and waits > for ever. This is with couchdb1.5.1 > > When I run the same code against my another couchdb server, only > difference being that the version is 1.5.0, it works perfect. All the > views return the right responses and results. > > Can anyone help me here? I am at a loss! > > Below is a snippet of my design doc: > > def createDesignDocForPerfStats(): > design = db.design('perfstats') > resp = design.put(params={ > "_id":"_design/perfstats", > "language": "javascript", > "views": > { > "by_server": { > "map": "function(doc) { if ((doc.type == > 'performance_stats')) emit([doc.Hostname,doc.test_id],{ > 'Start_time':doc.start_time ,'CPU': doc.CPU, 'Memory': doc.Memory, > 'FileSystem':doc.FileSystem }) }" > }, > "by_test_id": { > "map": "function(doc) { if ((doc.type == > 'performance_stats')) emit(doc.test_id,{ 'Server Name': doc.Hostname, > 'Start_time':doc.start_time, 'CPU': doc.CPU, 'Memory': doc.Memory, > 'FileSystem':doc.FileSystem }) }" > }, > "by_testid_starttime": { > "map": "function(doc) { if ((doc.type == > 'performance_stats')) emit([doc.test_id, doc.start_time],{ 'Server Name': > doc.Hostname, 'TestID':doc.test_id, 'CPU': doc.CPU, 'Memory': > doc.Memory, 'FileSystem':doc.FileSystem }) }" > }, > #view is > http://10.247.32.71:5984/longevity/_design/perfstats51/_view/server?group=true > "server": { > "map": "function(doc) { if ((doc.type == > 'performance_stats')) emit([doc.test_id, doc.Hostname],null ) }", > "reduce": "function(keys, values) {return (null)}" > }, > "cpu": { > "map": "function(doc) { if ((doc.type == > 'performance_stats')) emit(doc.test_id, doc.CPU) }", > "reduce": "function(keys, values) " > "{ " > "avg = Math.round(sum(values)/values.length);" > "return(avg)" > " }" > }, > #get avg cpu for all servers per time > # > http://10.247.32.72:5984/longevity/_design/perfstats1/_view/cpu_by_starttime?group=true > "cpu_by_starttime": { > "map": "function(doc) { if ((doc.type == > 'performance_stats')) emit([doc.test_id,doc.start_time], doc.CPU) }", > "reduce": "function(keys, values) " > "{ " > "avg = Math.round(sum(values)/values.length);" > "return(avg)" > " }" > }, > }, > "lists":{ > "sort":"function(head, req) {" > "var row;" > "var rows=[];" > "while(row = getRow()) {" > "rows.push(row)" > "};" > "rows.sort(function(a,b) {" > "return b.value-a.value" > "});" > "send(JSON.stringify({\"rows\" : rows[0]}))" > "}" > } > }) >