Return-Path: Delivered-To: apmail-incubator-couchdb-user-archive@locus.apache.org Received: (qmail 64768 invoked from network); 18 Nov 2008 15:27:21 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 18 Nov 2008 15:27:21 -0000 Received: (qmail 12103 invoked by uid 500); 18 Nov 2008 15:27:28 -0000 Delivered-To: apmail-incubator-couchdb-user-archive@incubator.apache.org Received: (qmail 12075 invoked by uid 500); 18 Nov 2008 15:27:28 -0000 Mailing-List: contact couchdb-user-help@incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: couchdb-user@incubator.apache.org Delivered-To: mailing list couchdb-user@incubator.apache.org Received: (qmail 12064 invoked by uid 99); 18 Nov 2008 15:27:27 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 18 Nov 2008 07:27:27 -0800 X-ASF-Spam-Status: No, hits=-0.0 required=10.0 tests=SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: domain of bjnortier@gmail.com designates 74.125.46.154 as permitted sender) Received: from [74.125.46.154] (HELO yw-out-1718.google.com) (74.125.46.154) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 18 Nov 2008 15:26:06 +0000 Received: by yw-out-1718.google.com with SMTP id 5so1265061ywr.0 for ; Tue, 18 Nov 2008 07:26:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:message-id:date:from:to :subject:in-reply-to:mime-version:content-type :content-transfer-encoding:content-disposition:references; bh=h3mdzeLGYmA0bulkCjf/2jgyM8Wb3Xt/amthnoSREmk=; b=nfP4635qfuQe1QeHS2NsKMC02JLD21qc1P8jBZroK7hsgpApz00hUUPH78ys489O71 AjbIVczWXQEK8x/JLD3REU5UDTtpkzMdrSp2g632gvkCY7zfXlV4l/t8lFnV4mfGQjGw YofWdhc3Il6kuJWZ2Apc8MMEekfIrnqJSaHFg= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:to:subject:in-reply-to:mime-version :content-type:content-transfer-encoding:content-disposition :references; b=DZZXIYk9mmc8x5zxwvTuQ8HUq3/KHRUmZAuXFLBzy/cmva/igihe5w5HKwG1KgtERL IvMwLegoUgVqXGbjhMrCHMepoHiFRkTqb68XmlEzOv0JUMTX+3Po2RRtbTKQh8wkKlU2 2g+0OA+hv480v5dQ3TveMyxxb7fa/3HA+07ws= Received: by 10.142.44.11 with SMTP id r11mr2641504wfr.249.1227022009851; Tue, 18 Nov 2008 07:26:49 -0800 (PST) Received: by 10.142.134.2 with HTTP; Tue, 18 Nov 2008 07:26:49 -0800 (PST) Message-ID: Date: Tue, 18 Nov 2008 15:26:49 +0000 From: "Benjamin Nortier" To: couchdb-user@incubator.apache.org Subject: Re: View with incremental counter In-Reply-To: MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline References: <4922C646.7010802@silencegreys.com> X-Virus-Checked: Checked by ClamAV on apache.org I would imagine that it's not very easy if you want to retain the ability to instantiate objects outside the function. But I'm no expert :) Ben On Tue, Nov 18, 2008 at 2:59 PM, Paul Davis wrote: > If this is easy and you see an implementation, I think it'd be a great > addition to force the sand boxing of individual functions. > > That said, I don't know much about the JS internals so I'm not sure > how hard it would be to auto detect what might cause side effects > outside the function and what wouldn't. I've stuck largish objects > outside the function itself on the assumption that they'll only be > instantiated once as opposed to once per document. > > I have absolutely no idea if that's even necessary though. > > Paul > > On Tue, Nov 18, 2008 at 9:51 AM, Benjamin Nortier wrote: >> Should CouchDB not restrict defining state outside the map function? >> I.e. you should not be able to declare a counter outside the function? >> >> On Tue, Nov 18, 2008 at 1:42 PM, Jedediah Smith >> wrote: >>> >>> You can't maintain a state across calls to map functions in this way. Map >>> functions can be called in any order or in parallel, any number of times on >>> a particular document and in completely separate environments. They should >>> not have any side effects or depend on any outside state. >>> >>> You should read up on Google's MapReduce and maybe functional programming in >>> general in order to understand how CouchDB works. >>> >>> If you just want to number the results of your view, that can be easily done >>> by the calling code. >>> >>> Adam Groves wrote: >>>> >>>> Hi, >>>> >>>> I've got the following view: >>>> >>>> count = 0; >>>> function(doc) { >>>> if(doc.type == "document") { >>>> count = count + 1 >>>> emit(doc._id, count); >>>> } >>>> } >>>> >>>> The idea is that I get a list of documents, each having a counter >>>> value which is incremental. I expected the count values to come out in >>>> order, but that isn't the case: my first few documents have values of >>>> 62, 61, 22, 19. I'm not quite sure what's going on here - any ideas >>>> how the order is being set here? >>>> >>>> Regards >>>> >>>> Adam Groves >>>> >>> >> >> >> >> -- >> Benjamin Nortier >> e: bjnortier@gmail.com >> c: +44 (0)778 946 1959 >> msn: bjnortier@mail.com >> gtalk: bjnortier@gmail.com >> > -- Benjamin Nortier e: bjnortier@gmail.com c: +44 (0)778 946 1959 msn: bjnortier@mail.com gtalk: bjnortier@gmail.com