Reputation: 4330
I have a view which counts reports for each city
function (doc) {
if(doc.type == "report")
{
emit(doc.city_name, null);
}
}
And I reduce it with _count
which produces these values:
{'key': 'South Tampa', 'value': 2}
{'key': 'Sebring', 'value': 19}
{'key': 'Satsuma', 'value': 3}
{'key': 'Palm Desert', 'value': 1}
{'key': 'Indio', 'value': 1}
At the moment I do a request with multiple keys to this view (for example ["Indio", "Satsuma"]
) and I sum them in python.
Is it possible to sum them with CouchDB directly?
Upvotes: 2
Views: 81
Reputation: 907
The Couchdb List function might be a possibility to achieve what you want.
http://docs.couchdb.org/en/2.1.2/ddocs/ddocs.html#list-functions
To get a better impression on how to use it this article might be helpfull. http://guide.couchdb.org/draft/transforming.html
A list function which sums them:
function(head, req){
i = 0;
while(row = getRow()){ i += row.value; }
send('{ \"total_count\":' + i +'}');
}
Upvotes: 1