Wednesday, January 29, 2014

How to count total attachments in a CouchDB database


You can watch the screencast here: How to count total attachments in a CouchDB database

And here's the source code for easy copy/paste:
function(doc) {
if (doc._attachments) {
for (var key in doc._attachments) {
// output filename, filesize, docId
emit([key,doc._attachments[key].length,doc._id], 1);
}
}
}
view raw map.js hosted with ❤ by GitHub
function(keys, values, rereduce) {
if (rereduce) {
return sum(values);
} else {
return values.length;
}
}
view raw reduce.js hosted with ❤ by GitHub

0 comments:

Post a Comment