couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Apache Wiki <wikidi...@apache.org>
Subject [Couchdb Wiki] Update of "View Snippets" by mdornseif
Date Fri, 26 Dec 2008 16:38:45 GMT
Dear Wiki user,

You have subscribed to a wiki page or wiki category on "Couchdb Wiki" for change notification.

The following page has been changed by mdornseif:
http://wiki.apache.org/couchdb/View_Snippets

New page:
This page collects code snippets to be used in your ["Views"]. They are mainly ment to help
getting your head arround the map/reduce approach to databases. Keep in mind that the the
Futon Web-Client silently adds group=true to your views.

== Get all documents which have an attatchment ==

This lists only the documents which have an attachment.

{{{
map: function(doc) {
  if (doc._attachments) {
    emit(doc._id, null);
  }
}
}}}

== Count documents which and without an attatchment ==

{{{
map: function(doc) {
  if (doc._attachments) {
    emit("with attatchment", 1);
  }
  else {
    emit("without attatchment", 1); 
  }
}
reduce: function(keys, values) {
   return sum(values);
}
}}}

Mime
View raw message