Return-Path: Delivered-To: apmail-couchdb-user-archive@www.apache.org Received: (qmail 58226 invoked from network); 28 Feb 2009 01:06:54 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 28 Feb 2009 01:06:54 -0000 Received: (qmail 86840 invoked by uid 500); 28 Feb 2009 01:06:47 -0000 Delivered-To: apmail-couchdb-user-archive@couchdb.apache.org Received: (qmail 86804 invoked by uid 500); 28 Feb 2009 01:06:47 -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 86792 invoked by uid 99); 28 Feb 2009 01:06:47 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 27 Feb 2009 17:06:47 -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 ben324@gmail.com designates 209.85.219.167 as permitted sender) Received: from [209.85.219.167] (HELO mail-ew0-f167.google.com) (209.85.219.167) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 28 Feb 2009 01:06:41 +0000 Received: by ewy11 with SMTP id 11so1570307ewy.11 for ; Fri, 27 Feb 2009 17:06:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:in-reply-to:references :date:message-id:subject:from:to:content-type :content-transfer-encoding; bh=gGA+43Ruy+LFQl9y9tzsjJcI28XWexqHkJ0z5z66S10=; b=gfzgSh4y9QxKCrnQ8usnr/RSFdZYaD1hMtNHfXXl2EhgHZAD/sUNnR9cpqpe8qzVhR vOxKMtxOPLm+DcGO6ustkyRxPC4gcILJsXReIc/cAR7kJgAvoqwQyx5m1K41SJ7qoPsb or01dl2ArkafbRKBduwOS+QwZ/jPIAykOn2XU= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type:content-transfer-encoding; b=dOUCDb0oTvwiRTup+4TbVPKUPKcwu4VW20KXQ+xTafEuV43dGzlfRkbRL5li1PVBN+ jIGPG6Ej6Q5TkL7MyvvgeRhp6ho8/Y5fRXzM1MMpKd9glbWS76Pen9kjueUszPfDgXeW fRYBd4U5oTHNhjnHdV2RXGI2DRMxWDDbvJzts= MIME-Version: 1.0 Received: by 10.210.21.13 with SMTP id 13mr905118ebu.43.1235783179663; Fri, 27 Feb 2009 17:06:19 -0800 (PST) In-Reply-To: References: <7db9abd30902271413h3d13c9ebq65dd6b834d6b5cca@mail.gmail.com> <56a83cd00902271422l7dc918e1h38676aab3b542ac4@mail.gmail.com> <7db9abd30902271427m1c600c61jaefc677b724cb686@mail.gmail.com> Date: Fri, 27 Feb 2009 20:06:19 -0500 Message-ID: Subject: Re: Reducing to unique values... From: Ben Browning To: user@couchdb.apache.org Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Virus-Checked: Checked by ClamAV on apache.org Does something as simple as this work? map: // This assumes "a" is in a doc field called key and "one" is in a field called value function(doc) { emit(doc.key, doc.value); } reduce: function(keys, values, rereduce) { // rereduce and regular reduce are the // same code here since they both just operate // on the values array and return an array var uniques = []; for (var i = 0; i < values.length; i++) { if (uniques.indexOf(values[i]) < 0) { uniques.push(values[i]); } } return uniques; } We just construct an array of unique values in the reduce. My simple testing shows this returns reduce values like {"rows":[{"key":"a","value":["two","one"]},{"key":"b","value":["three"]}]} for map values of {"total_rows":6,"offset":0,"rows":[ {"id":"34ab35d58a1540a24cea02aa6b97d2a6","key":"a","value":"one"}, {"id":"41099d0591233670250ebf146983cade","key":"a","value":"one"}, {"id":"70bd1f511ede201d93655f896ad4c99f","key":"a","value":"one"}, {"id":"c65afdfddfb3ea6a33cfd20e67364d11","key":"a","value":"two"}, {"id":"3b06e1ee7e63cd856aae52513f11bc51","key":"b","value":"three"}, {"id":"611a47c396492eb7b88190e81836427b","key":"b","value":"three"} ]}