You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
While it does not make sense to reduce data that belongs to many different users it would be interesting to still allow the user to decide how he wants to reduce in this case.
I would like to create a view statistics but I don't want that those statistics are available to everybody. So I would like to allow the following code bug currently the only function possible is _count (and if withOwner: true my reduce is ignored.
customViews.statsByOwner = {
map: function(doc) {
if (doc.$type !== 'entry') return;
for (var i = 0; i < doc.$owners.length; i++) {
emit(['[email protected]', doc.$kind, doc.$owners[i]], doc);
}
},
reduce: function(keys, values, rereduce) {
if (!rereduce) {
var result = {
entries: {
total: values.length,
reaction: values.filter(function(value) {
return value.$kind === 'reaction';
}).length,
sample: values.filter(function(value) {
return value.$kind === 'sample';
}).length,
analysisRequest: values.filter(function(value) {
return value.$kind === 'analysisRequest';
}).length
},
attachments: {
number: 0,
size: 0
}
};
values.forEach(function(value) {
if (value._attachments) {
var keys = Object.keys(value._attachments);
for (var i = 0; i < keys.length; i++) {
result.attachments.number++;
result.attachments.size += value._attachments[keys[i]].length;
}
}
});
return result;
} else {
var result = values[0];
for (var i = 1; i < values.length; i++) {
var value = values[i];
result.entries.total += value.entries.total;
result.entries.sample += value.entries.sample;
result.entries.reaction += value.entries.reaction;
result.entries.analysisRequest += value.entries.analysisRequest;
result.attachments.number += value.attachments.number;
result.attachments.size += value.attachments.size;
}
return result;
}
},
designDoc: 'stats',
withOwner: true
The text was updated successfully, but these errors were encountered:
It's not just about allowing it. The problem is that for the reduce, you need to take care of the fact that the same document will be emitted multiple times (once for each owner).
While it does not make sense to reduce data that belongs to many different users it would be interesting to still allow the user to decide how he wants to reduce in this case.
I would like to create a view statistics but I don't want that those statistics are available to everybody. So I would like to allow the following code bug currently the only function possible is _count (and if
withOwner: true
my reduce is ignored.The text was updated successfully, but these errors were encountered: