couchdb查询映射视图而不是缩减视图
如何使用evetly查询既有map又有reduce的视图的map 以下是我目前在data.js中的内容:couchdb查询映射视图而不是缩减视图,couchdb,couchapp,Couchdb,Couchapp,如何使用evetly查询既有map又有reduce的视图的map 以下是我目前在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(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}
};
我想让它返回查询中的总行数及其值的平均值
提前感谢您的帮助。我现在手头没有couchapp可供测试,但我认为您对CouchDB视图映射功能感到困惑。执行
data.rows.map()
您正在调用data.rows
数组上的Array.map
函数。您要查找的内容应该在数据中。总计行数中
阅读了解更多信息
更新:行数为data.rows.length