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": [
        {
            "doc": {
                "language": "javascript",
                "version": 1,
                "views": {
                    "seen": {
                        "map": "function(doc) { if (doc.threadId && 
doc.comments) { emit(doc.threadId.toLowerCase(), doc.comments); } }",
                        "reduce": "function(key, values) { var s = 0; for(i 
= 0; i < values.length; i++) { s += values[i]; } return s; }"
                    }
                },
                "_rev": "1-a75768a5fc3b5cc2304adc7d5bfb37f6",
                "_id": "_design/fabric"
            },
            "id": "_design/fabric",
            "key": "_design/fabric",
            "value": {
                "_conflicts": [],
                "rev": "1-a75768a5fc3b5cc2304adc7d5bfb37f6"
            }
        }
    ]
}

My understanding is that reduce only happens when group=true is supplied 
via query string right?

So Im calling GET on 
http://localhost:5984/database/_design/fabric/_view/seen?group=true
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 :-)


On Tuesday, February 24, 2015 at 11:52:30 AM UTC-5, Jens Alfke wrote:
>
> function(keys, values, rereduce) { 
>         var total = 0; 
>         for (var i=0; i<values.length; i++) 
>                 total += values[i]; 
>         return total; 
> } 
>
> —Jens

-- 
You received this message because you are subscribed to the Google Groups 
"Couchbase Mobile" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/mobile-couchbase/ee5c65c8-3a9e-443f-aacd-5d7bf03510f9%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to