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 "Introduction to CouchDB views" by TimSomers
Date Mon, 06 Apr 2009 08:46:33 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 TimSomers:
http://wiki.apache.org/couchdb/Introduction_to_CouchDB_views

The comment on the change is:
I'm using eval(uneval(obj)) to create a clone, anyone know a cleaner solution?

------------------------------------------------------------------------------
  }}}
  
  ''This example output was reformatted for readability.''
+ 
+ Keep in mind that emit works by just storing the key/value pairs in an array and then, when
all views in the same _design document have been calculated, returns all results at once.
So if you use an object to make calculations and do multiple emits on the same document, you
must create a copy and not emit the same object multiple times. For example:
+ 
+ {{{
+ function(doc) {
+   if (doc.Type == "measurement") {
+     var timestamp = new Date(doc.timestamp)
+     emit(eval(uneval(timestamp)), doc.lastTemp);
+     timestamp.setSeconds(timestamp.getSeconds - 30);
+     emit(eval(uneval(timestamp)), doc.temp30secsAgo);
+     timestamp.setSeconds(timestamp.getSeconds - 30);
+     emit(eval(uneval(timestamp)), doc.temp1minAgo);
+   }
+ }
+ }}}
  
  === Reduce Functions ===
  

Mime
View raw message