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:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function(doc) { | |
if (doc._attachments) { | |
for (var key in doc._attachments) { | |
// output filename, filesize, docId | |
emit([key,doc._attachments[key].length,doc._id], 1); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function(keys, values, rereduce) { | |
if (rereduce) { | |
return sum(values); | |
} else { | |
return values.length; | |
} | |
} |
0 comments:
Post a Comment