You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by Apache Wiki <wi...@apache.org> on 2008/12/26 17:38:45 UTC
[Couchdb Wiki] Update of "View Snippets" by mdornseif
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);
}
}}}