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 2009/05/06 17:11:25 UTC

[Couchdb Wiki] Update of "View server" by Tunde

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 Tunde:
http://wiki.apache.org/couchdb/View_server

------------------------------------------------------------------------------
  CouchDB sends:
  
  {{{
- ["add_fun", "function(doc) { map(null, doc); }"]\n
+ ["add_fun", "function(doc) { if(doc.score > 50) emit(null, {"player_name": doc.name}); }"]\n
  }}}
  
  When the view server can evaluate the function and make it callable, it returns:
@@ -65, +65 @@

  CouchDB sends:
  
  {{{
- ["map_doc", {"_id":"8877AFF9789988EE","_rev":46874684684,"field":"value","otherfield":"othervalue"}]\n
+ ["map_doc", {"_id":"8877AFF9789988EE","_rev":3-235256484,"name":"John Smith","score": 60}]\n
  }}}
  
  If the function above is the only function stored, the views server answers:
  
  {{{
- [[[null, {"_id":"8877AFF9789988EE", "_rev":46874684684, "field":"value", "otherfield":"othervalue"}]]]\n
+ [[[null, {"player_name","John Smith"}]]]\n
  }}}
  
- That is, an array with the result for every function for the given document. If a document is to be excluded from the View, the array should be empty.
+ That is, an array with the result for every function for the given document.
+ 
+ If a document is to be excluded from the View, the array should be empty.
+ 
+ CouchDB sends:
+ 
+ {{{
+ ["map_doc", {"_id":"9590AEB4585637FE","_rev":1-674684684,"name":"Jane Parker","score": 43}]\n
+ }}}
+ 
+ The views server answers:
+ 
+ {{{
+ [[[]]]\n
+ }}}
+ 
+ 
+ 
  === reduce ===
  
  If the view has a {{{reduce}}} function defined, CouchDB will enter into the reduce phase. The view server will receive a list of reduce functions and some map results on which it can apply them. The map results are given in the form {{{[[key, id-of-doc], value]}}}.