couchdb-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Paul Davis <paul.joseph.da...@gmail.com>
Subject Re: Reduce Question
Date Mon, 14 Dec 2009 23:46:37 GMT
On Mon, Dec 14, 2009 at 6:32 PM, Andreas Pavlogiannis
<paulogiann.couchdb@gmail.com> wrote:
> Hello,
>
> I have created a filesystem so that each document is either a file or a
> folder (having the respective attribute), and has it's path stored in a
> list. For example document /root/home/photos/party has a path attribute:
> ['root', 'home', 'photos']. I would like to have a reduce function in order
> to calculate the total size of each file and folder, and each time get the
> result using the key value in queues.
>
> Is it possible? And if so, could you provide me some pointers please?
>
> Thanks,
>
> Andreas
>

//map function:
function(doc) {
    if(doc.is_file) emit(doc.path_as_array, doc.file_size);
}

//reduce function:
function(keys, values, rereduce) {
   return sum(values);
}

# Query:
$ curl 'http://127.0.0.1:5984/db_name/_design/filesystem/_view/file_sizes?key=["root","home","photos"]'

HTH,
Paul Davis

Mime
View raw message