I'm new to Couchdb. I want to calculate an average of a value in futon.
My map-function:
function(doc) {
if(doc.Fares.Taxes)
emit(1, doc.Fares.Taxes);
}
My reduce-function:
function(amount,values){
return sum(values/amount);
}
I'm new to Couchdb. I want to calculate an average of a value in futon.
My map-function:
function(doc) {
if(doc.Fares.Taxes)
emit(1, doc.Fares.Taxes);
}
My reduce-function:
function(amount,values){
return sum(values/amount);
}
You have built in support for sum
and count
and you have stats
; you should be able to use them to calculate it: http://wiki.apache.org/couchdb/Built-In_Reduce_Functions
You also have a sample of how to calculate sum "manually" in the "Cookbook": http://guide.couchdb.org/draft/cookbook.html#aggregate You should be able to extend that sum sample to calculate an avg instead.