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 0754AB652 for ; Sun, 8 Jan 2012 03:36:26 +0000 (UTC) Received: (qmail 15400 invoked by uid 500); 8 Jan 2012 03:36:20 -0000 Delivered-To: apmail-couchdb-user-archive@couchdb.apache.org Received: (qmail 15166 invoked by uid 500); 8 Jan 2012 03:35:53 -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 14866 invoked by uid 99); 8 Jan 2012 03:35:31 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 08 Jan 2012 03:35:31 +0000 X-ASF-Spam-Status: No, hits=-0.7 required=5.0 tests=RCVD_IN_DNSWL_LOW,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (nike.apache.org: domain of zachary.zolton@gmail.com designates 209.85.210.52 as permitted sender) Received: from [209.85.210.52] (HELO mail-pz0-f52.google.com) (209.85.210.52) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 08 Jan 2012 03:35:23 +0000 Received: by dadp15 with SMTP id p15so2606861dad.11 for ; Sat, 07 Jan 2012 19:35:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :content-type:content-transfer-encoding; bh=zY4dW21oyD1YPvF2sTMUQNIpTBcC0nIZphmk1W5Iyzw=; b=cMD6Sc3JFC0UcaPIvdPQjRxWMeQ4uPhVCtqsNm4qxZt2vBAVI/CR6y9sxrQt5bQmKV L7c8SML4D7UryFWxNS+p4qLpl2xL65szopchKdCHbIh1k0meReiQ79lgR5tE/NAJ4e1z BZLDM+GYu5DERYL05oZ6KtSQQ6yXUJZUMGmiI= Received: by 10.68.73.68 with SMTP id j4mr28518983pbv.40.1325993702314; Sat, 07 Jan 2012 19:35:02 -0800 (PST) MIME-Version: 1.0 Received: by 10.142.126.8 with HTTP; Sat, 7 Jan 2012 19:34:32 -0800 (PST) In-Reply-To: References: <37E896DC-095B-4AAA-AA5C-67AAE7C3B46D@p3k.org> From: Zachary Zolton Date: Sat, 7 Jan 2012 21:34:32 -0600 Message-ID: Subject: Re: Newbie question: How to collate sum() with other properties To: user@couchdb.apache.org Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: quoted-printable X-Virus-Checked: Checked by ClamAV on apache.org Tobi, I think it's better to get tricky with the keys emitted, and keep the reduction using the built-in Erlang implementations. How about this? map: function(doc) { var key; switch (doc.type) { case 'poll': key =3D [doc._id, 0, doc.title]; case 'vote': key =3D [doc.poll_id, 1, doc.choice]; } emit(key, null); } reduce: _count Then, and query using group=3Dtrue, and you'll get a result like this: {"rows":[ {"key":["d193f1137ddb65aa14100a51dc61b17e",0,"What is the question?"],"value":1}, {"key":["d193f1137ddb65aa14100a51dc61b17e",1,"Choice 1"],"value":1} ]} Would this suffice, for an all-in-one query? Cheers, Zach On Sat, Jan 7, 2012 at 9:03 PM, Zachary Zolton w= rote: > Well, if you know you're not going to keep adding properties, you can > always set reduce_limit =3D false in your config. > > 2012/1/7 Tobi Sch=E4fer : >> thanks for your suggestion, zach! >> >> i am delighted to hear that issuing two requests is not despised. >> >> nevertheless, just for the sake of fully understanding map/reduce in cou= chdb, i read your reply as although it might be a mess of code and counter-= intuitive it is possible and it would work=85 is that correct? >> >> best regards, >> tobi >> >> >> On 06.01.2012, at 18:57, Zachary Zolton wrote: >> >>> Tobi, >>> >>> You probably can somehow cram all that stuff together via the reduce >>> function, but you miss out on being able to use the built in _count >>> reduction and it'll take a mess of code. >>> >>> I think you're better off trying to retrieve this information in two >>> queries: first query for the names and IDs of the polls and then do a >>> second query for the count of choices of those poll IDs. >>> >>> >>> Cheers, >>> >>> Zach >>