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/04/06 10:46:33 UTC
[Couchdb Wiki] Update of "Introduction to CouchDB views" by TimSomers
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 ===