couchdb-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Robert Newson <rnew...@apache.org>
Subject Re: [object Object] instead of string
Date Sun, 15 Jan 2012 15:48:08 GMT
It's probably just bad luck. Your reduce function does not reduce
enough (so it would hit reduce_overflow at some point).

I think what you're trying to do is to get the count of any top-level
key in your document?

Something like;

map:
for (var key in doc) {
    if(key != '_id' && key != '_rev'){
        emit([doc.page_id, doc.date, key], null);
    }
}

reduce:
_count

would avoid reduce_overflow errors. You can get the count of all the
items for a particular object with ?startkey=[page_id,
date]&endkey=[page_id, date, {}]&group=true

B.


On 15 January 2012 15:15, Gabriel de Oliveira Barbosa
<manobi.oliveira@gmail.com> wrote:
> Just can't understand why in second how it working, given that all
> documents have the same structure:
>
> function map (doc){
> for(var key in doc){
> var output = {};
> if(key != '_id' && key != '_rev'){
>  output[key] = doc[key];
> emit(doc.page_id + ':' + doc.date, output);
>  }
> }
> };
>
> function reduce (keys, values, rereduce){
>  var hash = {};
>
> values.forEach(function(pair){
> for(var key in pair){
>  hash[key] = hash[key] || {};
> hash[key][pair[key]] = (hash[key][pair[key]] + 1) || 1;
>  }
> });
>  return hash;
> };

Mime
View raw message