incubator-couchdb-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Wout Mertens <wout.mert...@gmail.com>
Subject Re: I'm going mad with reduce
Date Fri, 14 Aug 2009 16:20:55 GMT
Why don't you simply emit a row for each value in Standard? That will  
then become unique rows in the reduce. You'll have to read multiple  
rows to get all the values though.

Wout.

On Aug 14, 2009, at 3:41 PM, Thomas.Bock@ptb.de wrote:

> Dear users,
>
> I like to provide check-box input with a view.
> The couchdb contains  an key named Standard with
> 90 values "CE3", 2 values "SE2", 1 value "C1" ...
>
> Now the view should deliver each value 1 times.
> After two hours playing with reduce I give up at this point:
>
> map:function(doc) {
> if(doc.Calibration.Standard){
> var standard = doc.Calibration.Standard;
> ;
>  emit(standard, {"Standard": standard });
> }
> }
> reduce:function(k, v, c){
>
> var res = {};
> var star = new Array();
> var j =0;
>
> for(var i=0; i< v.length; i++) {
>
> var stdr = v[i].Standard;
>
> if(!(res[stdr])){
>
> res[stdr] = ;
> star[j] = v[i].Standard;
> j +=1;
>
> }
>
> }
> var conStr = star.toString();
> var back = {Standard:conStr}
> return back ;
>
> }
>
> I get something like
> {"rows":[
> {"key":null,"value":{"Standard":"CE3,SE2,CE3,CE2,CE1"}}
> ]}
>
>
> When I use the "raw" http://server:5984/db/_design/reduce/_view/standard-1
> you see that CE3 is listed two times ??
>
> I think this is a kick self problem,
> can you kick me?
>
> Regards
> Thomas
>
>


Mime
View raw message