How do I query just the map of a view with both a map and reduce using evently?
Here is what I have so far in data.js:
function(data) {
var numRows = data.rows.map(function(r) {
return r
}); //this is returning an object that is the result of the reduce function
// but I want the total_rows of the map function
var sum = data.rows.reduce(function(r) {
return r.value
}); //this returns the sum of all row values
var avg = sum.value / numRows
$.log(avg);
$.log(numRows);
return {'total': numRows, 'average': avg}
};
I want this to return the total number of rows from the query and the average of their values.
Thanks in advance for the help.
I do not have couchapp at hand right now to test, but I think you are confusing JavaScript map function with CouchDB view map function. Doing
data.rows.map()
you are calling theArray.map
function on thedata.rows
array. What you are looking for should be indata.total_rows
.Read this tutorial for more information.
UPDATE: the number of rows is data.rows.length.