The reduce function Im using is:
function(key, values) { var s = 0; for(i = 0; i < values.length; i++) { s += values[i]; } return s; }
But the combined map-reduce doesn't produce what I want which is totals for each thread.
The data Im working with is simple: documents containing a threadId and a counter, e.g.
{
threadId: "78d7bb17-7c89-456f-82e8-e18f1727c1f7",
comments: 1
}
The complete design doc for my view looks like this:
{
"total_rows": 1,
"offset": 0,
"rows": [
{
"rev": "1-a75768a5fc3b5cc2304adc7d5bfb37f6"
}
}
]
}
My understanding is that reduce only happens when group=true is supplied via query string right?
The output Im getting shows the total for all documents and only one threadId even though my sample data is four documents conmtaining two unique threads with totals.
For sure, Im misunderstanding :-)