incubator-couchdb-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Nicolas Clairon <clai...@gmail.com>
Subject Re: Random issue with reduce
Date Sat, 28 Mar 2009 11:25:13 GMT
I use this form of reduce to group by key the results.
In the real life, I use this reduce to get all tag group by document id.

Something like that :

function(doc){
   if(doc.doc_type == "MyDoc"){
     for( var t in doc.tags){
       emit(doc.name, doc.tags[t]);
     }
   }
}

and the reduce :

function(key, values){
  return values;
}

I get the following result:

name1 = > ["tag1", "tag2", "tag3"]
name2 => ["tag2", "tag3"]

but sometime I get this result

name1 = [["tag1","tag2","tag3"],["tag4","tag5","tag6","tag7"],["tag8","tag9"]]

Note that if the view work well the first time, it will always work fine.

It is the correct way to go ?

On Sat, Mar 28, 2009 at 12:10 PM, Sven Helmberger
<sven.helmberger@gmx.de> wrote:
> Nicolas Clairon schrieb:
>>
>> Nop !
>>
>> Here is the test  map function :
>>
>> function(doc){
>>  emit("key", 1);
>> }
>>
>> and the reduce function:
>>
>> function(key, values){
>>  return values;
>> }
>>
>> That work well for a large usecase but sometime, I get this strange
>> behavior...
>>
>
> What purpose does the reduce function have? it doesn't really reduce or
> combine anything so it seems like it could just as well be left out.
>
> Regards,
> Sven Helmberger
>

Mime
View raw message