0

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);
}
Weedjo
  • 335
  • 1
  • 6
  • 17

1 Answers1

1

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.

Daniel
  • 8,133
  • 5
  • 36
  • 51