List attachment filenames in couchDB

List through the documents that have an attachment and list them by a field called “name” that are on each document in this particular DB and then the filename that are a variable we assign the value to in the for loop.

function(doc) {
  if(doc._attachments) {
    var filename;
    for (var key in doc._attachments) {
      if (doc._attachments.hasOwnProperty(key) && typeof(key) !== 'function') {
       filename = key;

    emit(, filename);

Add your comment