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;
};
