Reputation: 35
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.
Upvotes: 2
Views: 445
Reputation: 3901
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 the Array.map
function on the data.rows
array. What you are looking for should be in data.total_rows
.
Read this tutorial for more information.
UPDATE: the number of rows is data.rows.length.
Upvotes: 2