Return-Path: X-Original-To: apmail-couchdb-user-archive@www.apache.org Delivered-To: apmail-couchdb-user-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 305421693 for ; Wed, 20 Apr 2011 14:45:41 +0000 (UTC) Received: (qmail 22170 invoked by uid 500); 20 Apr 2011 14:45:39 -0000 Delivered-To: apmail-couchdb-user-archive@couchdb.apache.org Received: (qmail 22125 invoked by uid 500); 20 Apr 2011 14:45:39 -0000 Mailing-List: contact user-help@couchdb.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: user@couchdb.apache.org Delivered-To: mailing list user@couchdb.apache.org Received: (qmail 22117 invoked by uid 99); 20 Apr 2011 14:45:39 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 20 Apr 2011 14:45:39 +0000 X-ASF-Spam-Status: No, hits=-0.7 required=5.0 tests=FREEMAIL_FROM,RCVD_IN_DNSWL_LOW,RFC_ABUSE_POST,SPF_PASS,T_TO_NO_BRKTS_FREEMAIL X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: domain of mrtrick@gmail.com designates 209.85.212.172 as permitted sender) Received: from [209.85.212.172] (HELO mail-px0-f172.google.com) (209.85.212.172) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 20 Apr 2011 14:45:31 +0000 Received: by pxi6 with SMTP id 6so570303pxi.31 for ; Wed, 20 Apr 2011 07:45:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:message-id:date:from:user-agent:mime-version:to :subject:references:in-reply-to:content-type :content-transfer-encoding; bh=Ns2gA69sdBC6UvBgqryR7u9sBb6LScY2D0+gNoVvhgw=; b=L/Azf+4e4g0b+AoRCyhmthoUcpJDzrjJojWk0VtNc+y6PGJCTFIafTeTyTOrjF6Y/v OoIKcqvQghseC1xsuX0WVdjRqFsTHga+CmFHfx/SQvFlQ20jIlI2Ccfn0Ks4Ms1ItgQp jb1htsDVWwVhb4d485BmgNV+fQKyuzAaUUWEI= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:user-agent:mime-version:to:subject:references :in-reply-to:content-type:content-transfer-encoding; b=k3PSr13ezxySTl21G1pRTk8W9nnDO7tgip3Q1tLZJDgcw3JPEKOnQyXaquuk0IuKzb Mtlu9BW5LvJc8aQgI3MiSlBiDAzOCuyEMqyYRO9nnwSwSMzvBaLpYD3fH3/aUfFTuA4e s1wC4SWU4F0+SLbZwga06E1oBHi3snCkeQg/I= Received: by 10.68.37.36 with SMTP id v4mr3695224pbj.76.1303310711334; Wed, 20 Apr 2011 07:45:11 -0700 (PDT) Received: from [192.168.1.100] ([115.187.236.96]) by mx.google.com with ESMTPS id i7sm672380pbs.19.2011.04.20.07.45.08 (version=TLSv1/SSLv3 cipher=OTHER); Wed, 20 Apr 2011 07:45:09 -0700 (PDT) Message-ID: <4DAEF166.3020706@gmail.com> Date: Thu, 21 Apr 2011 00:44:54 +1000 From: Patrick Barnes User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2.15) Gecko/20110303 Lightning/1.0b2 Thunderbird/3.1.9 MIME-Version: 1.0 To: user@couchdb.apache.org Subject: Re: Dealing with sealed docs References: <6084E307-7CFB-4BAD-A12C-063272628B95@vpro.nl> <95333123-2B25-4E26-8C8A-D502C88D96B3@apache.org> In-Reply-To: <95333123-2B25-4E26-8C8A-D502C88D96B3@apache.org> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Actually, he is... if doc.events is an object, then the object might not actually be copied, but only a reference. If you change var events = doc.events; to var events = clone doc.event; Does that fix it? On 20/04/2011 10:59 PM, Jan Lehnardt wrote: > > On 20 Apr 2011, at 14:11, Nils Breunese wrote: > >> 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); >> } >> }); >> } >> }); >> } >> } >> } >> 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? > > I use JSON.parse(JSON.stringify(doc)) but that is essentially the same :) > > The reason that doc modifications work were an artefact of a bug in Spidermonkey that finally got resolved. You shouldn't rely on being able to modify a doc in map functions. > > That said, I'm surprised you get this error as you are not assigning anything do doc.events. Unless I got wrong how chaining in JS works, this shouldn't be a problem: > > js> var a = {a:1}; > js> seal(a); > js> a.a = 2; > typein:4: Error: a.a is read-only > js> var b = a.a; > js> print(b); > 1 > js> b = 2 > 2 > js> > > Cheers > Jan