Hello all,

I recently upgraded to CouchDB 1.0.2 for development and found some of our view 
map functions broke. Apparently it's no longer possible to modify data a doc in 
a view function before emitting. I found "Documents are now sealed before being 
passed to map functions." in the changelog for 1.0.2.

This is an example of a map function which no longer works under 1.0.2:

----
function(doc) {
  if(doc.type === 'schedule') {
    var events = doc.events;
    if (events) {
      events.forEach(function(event) {
        var broadcasters = event.broadcasters;
        if (broadcasters) {
          broadcasters.forEach(function(broadcaster) {
            if(broadcaster === 'VPRO') {
              event.channel = doc.channel;
              event.channelName = doc.channelName;
              emit(event.end, event);
            }
          });
        }
      });
    }
  }
}
----

A colleague suggested using this:

----
events.forEach(function(e) {
  var event = eval(uneval(e));
----

This creates a deep copy before modifying event properties. It works, but it 
looks ugly to me. Is this the way to go or is there a cleaner way?

Nils.
------------------------------------------------------------------------
 VPRO   www.vpro.nl
------------------------------------------------------------------------

Reply via email to