Return-Path: Delivered-To: apmail-couchdb-user-archive@www.apache.org Received: (qmail 34796 invoked from network); 10 Apr 2009 13:33:34 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 10 Apr 2009 13:33:34 -0000 Received: (qmail 27191 invoked by uid 500); 10 Apr 2009 13:33:33 -0000 Delivered-To: apmail-couchdb-user-archive@couchdb.apache.org Received: (qmail 27096 invoked by uid 500); 10 Apr 2009 13:33:33 -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 27086 invoked by uid 99); 10 Apr 2009 13:33:32 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 10 Apr 2009 13:33:32 +0000 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 wout.mertens@gmail.com designates 209.85.146.181 as permitted sender) Received: from [209.85.146.181] (HELO wa-out-1112.google.com) (209.85.146.181) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 10 Apr 2009 13:33:23 +0000 Received: by wa-out-1112.google.com with SMTP id m38so603459waf.27 for ; Fri, 10 Apr 2009 06:33:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:cc:message-id:from:to :in-reply-to:content-type:content-transfer-encoding:mime-version :subject:date:references:x-mailer; bh=hyeNuGZ9ABporXm9Ly++O84UtX5z+vo/Vm+jtkSnnJ0=; b=jaOtSY9GOFoI5EyGahbz/JQUP+Qf/YCqqc9I9fUmORhvM8VscQwbZfmBjFqMCHDTuQ CHADXwhdaspVETq8mQznP2jumKz3cZOwCq+NHe3DZIaVj3tubanbGLu/9edk3dFjKist 1+hyVd4iO0qjg+Xn0B5K6/Kg9lzFE9/ua6Nn8= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=cc:message-id:from:to:in-reply-to:content-type :content-transfer-encoding:mime-version:subject:date:references :x-mailer; b=glik7FrGeqG6NO1bRmQgrVnVEs4qE51AnWK7xTiVP8uLqg9ODB7ipTo8wXZTEKHDtc 88Xk5Sw09RmMDaskVrIsOAvspFwIbg0/XNem8mSEIJiTLQk+JbBvLoRWpUjfvauXC9Yc 6MSBOFj7OTSgVOibTby3p16mQMv8MAt9Uq4io= Received: by 10.114.75.1 with SMTP id x1mr1912179waa.107.1239370383614; Fri, 10 Apr 2009 06:33:03 -0700 (PDT) Received: from dhcp-peg3-cl31144-254-5-147.cisco.com (dhcp-peg3-cl31144-254-5-147.cisco.com [144.254.5.147]) by mx.google.com with ESMTPS id l28sm1427031waf.30.2009.04.10.06.33.01 (version=TLSv1/SSLv3 cipher=RC4-MD5); Fri, 10 Apr 2009 06:33:02 -0700 (PDT) Cc: user@couchdb.apache.org Message-Id: <92DC1E7B-BDEB-4B8E-B84D-E7CF734D5A17@gmail.com> From: Wout Mertens To: Wout Mertens In-Reply-To: <3EA1C6DC-6331-4068-A89C-DBC462D0B890@cisco.com> Content-Type: text/plain; charset=US-ASCII; format=flowed; delsp=yes Content-Transfer-Encoding: 7bit Mime-Version: 1.0 (Apple Message framework v930.3) Subject: Re: [user] Obtaining unique values from a view Date: Fri, 10 Apr 2009 15:32:58 +0200 References: <55fad2460903030527r1295a39bl675478e8a9c5266d@mail.gmail.com> <3EA1C6DC-6331-4068-A89C-DBC462D0B890@cisco.com> X-Mailer: Apple Mail (2.930.3) X-Virus-Checked: Checked by ClamAV on apache.org Note to self: I now realize that the easiest way (perhaps the best) to do the below is to have your function be map: function(doc) { if (doc.Experiment) for (i in doc.Conditions){ emit([doc.Experiment, i], 1); } } reduce: function(key,values,rereduce) { return sum(values); } This gives you rows like {"key":["Something","X"],"value":3} {"key":["Something","Y"],"value":4} where value is the count. You can replace 1 and the sum with null if you're not interested in the count. This is way better than a unique() function because it calculates in constant time and memory and you can request subranges of values. Wout. On Mar 3, 2009, at 2:38 PM, Wout Mertens wrote: > I believe this has been covered in this thread: > http://markmail.org/thread/lwqfwlscrvilwm34 > > but I think a totally satisfactory answer was not found. > > Wout. > > On Mar 3, 2009, at 2:27 PM, Manolo Padron Martinez wrote: > >> Hi: >> >> I'm really a newbie, and I have a newbie problem (and maybe a miss >> conception of the way to work with couch). >> I have a lot of documents with this form (that represents >> experiments with >> any number of conditions, so X and Y could be only X or even >> X,Y,Z...) >> >> { >> "Experiment":"something", >> "Conditions": >> { >> "X":3, >> "Y":2 >> } >> } >> >> And I have a view like: >> MAP: >> >> function(doc) { >> if (doc.Experiment) >> for (i in doc.Conditions){ >> emit(doc.Experiment, i); >> } >> } >> >> REDUCE: >> >> function(key,values) >> { >> return values; >> } >> >> When I launch the view I get this: >> >> {"rows":[{"key":"Something","value":["X","Y"]}, >> {"key":"Something2","value": >> ["X","Y","X","Y","X","Y","Z","X","Y","X","Y","X","Y","Z"]}]} >> >> >> >> I would like to get what are the conditions for every experiment >> grouped by >> experiment without repetitions (I mean something like) >> >> {"rows":[{"key":"Something","value":["X","Y"]}, >> {"key":"Something2","value":["X","Y","Z"]}]} >> >> >> Anyone could help me? >> >> Regards from Canary Island >> >> Manuel Padron Martinez >