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 2010/02/23 10:51:29 UTC

[Couchdb Wiki] Update of "Introduction_to_CouchDB_views" by SebastianCohnen

Dear Wiki user,

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

The "Introduction_to_CouchDB_views" page has been changed by SebastianCohnen.
The comment on this change is: Added TOC; added sytax HL for JS-Code.
http://wiki.apache.org/couchdb/Introduction_to_CouchDB_views?action=diff&rev1=31&rev2=32

--------------------------------------------------

+ = Introduction to CouchDB Views =
+ <<TableOfContents(2)>>
+ 
  A simple introduction to CouchDB views.
  
  == Concept ==
@@ -23, +26 @@

  === Map Functions ===
  Here is the simplest example of a map function:
  
- {{{
+ {{{#!highlight javascript
  function(doc) {
    emit(null, doc);
  }
@@ -34, +37 @@

  
  Here is a slightly more complex example of a function that defines a view on values computed from customer documents:
  
- {{{
+ {{{#!highlight javascript
  function(doc) {
    if (doc.Type == "customer") {
      emit(null, {LastName: doc.LastName, FirstName: doc.FirstName, Address: doc.Address});
@@ -45, +48 @@

  
  To be able to filter or sort the view by some document property, you would use that property for the key. For example, the following view would allow you to lookup customer documents by the ''!LastName'' or ''!FirstName'' fields:
  
- {{{
+ {{{#!highlight javascript
  function(doc) {
    if (doc.Type == "customer") {
      emit(doc.LastName, {FirstName: doc.FirstName, Address: doc.Address});