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 80975603E for ; Tue, 7 Jun 2011 06:22:09 +0000 (UTC) Received: (qmail 69401 invoked by uid 500); 7 Jun 2011 06:22:07 -0000 Delivered-To: apmail-couchdb-user-archive@couchdb.apache.org Received: (qmail 69325 invoked by uid 500); 7 Jun 2011 06:22:03 -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 69300 invoked by uid 99); 7 Jun 2011 06:22:01 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 07 Jun 2011 06:22:01 +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 torsteinkrausework@gmail.com designates 209.85.210.180 as permitted sender) Received: from [209.85.210.180] (HELO mail-iy0-f180.google.com) (209.85.210.180) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 07 Jun 2011 06:21:56 +0000 Received: by iyf40 with SMTP id 40so8689955iyf.11 for ; Mon, 06 Jun 2011 23:21:35 -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=6Ua1oF5Zya06mKlTsDuGo3XIPO9nnvnyqATB86RGHMM=; b=RK7GyVo3R0L262wYwJdMWbIHFX2t/yCwGT9QT9CG2t4heqlXwnkyAloGlTbw1HIfGg iQUKZnGQp2RzD6vPKFjdfuZg+i9hSNAm29Rg7DAh8rjHvNoCH7HJEZFQnL+By7Toa1FM JA6CozV3J0dZ5A28D3fYSWtVEZhW0fLmHBdnA= 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=T3gBYwmDGcElNqDCFaJZ/g/qYfw7KvIKF7xlkuhcrQm/Uiv/d2N7i1ffA0fnzqYRh3 8JD11xu/KrJZpuerfKVsknVPqysKOVLOb+gnoUHAYFQ0H2i+0ck32vSGYWbG4+b8vV5P AmkUefFsBd6yHJPsCAsauEGPQh2nTCpykwbng= Received: by 10.231.82.193 with SMTP id c1mr9201857ibl.177.1307427695821; Mon, 06 Jun 2011 23:21:35 -0700 (PDT) Received: from [192.168.1.105] (114-40-26-249.dynamic.hinet.net [114.40.26.249]) by mx.google.com with ESMTPS id v16sm2012314ibe.51.2011.06.06.23.21.33 (version=SSLv3 cipher=OTHER); Mon, 06 Jun 2011 23:21:34 -0700 (PDT) Message-ID: <4DEDC36C.5090207@gmail.com> Date: Tue, 07 Jun 2011 14:21:32 +0800 From: Torstein Krause Johansen User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.17) Gecko/20110510 Icedove/3.1.10 MIME-Version: 1.0 To: user@couchdb.apache.org Subject: Re: Complex queries & results References: <4DDDFD4E.9060701@gmail.com> <4DDF164A.7030009@gmail.com> <4DDF6BEE.8070907@gmail.com> <4DE4F6F4.9000406@couchone.com> <4DECC426.9070201@gmail.com> In-Reply-To: Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 7bit Hi Sean, and thank you so much for your reply. On 06/06/11 22:09, Sean Copenhaver wrote: > Anyway, back to what you are trying to accomplish. Honestly it sounds like > you are trying to get too advanced for the built-in _count or _sum reduce > functions. Have you tried writing a custom reduce function that does the > grouping how you want, basically by name alone? > > https://gist.github.com/1010318 > > I tried this out with 10 docs fitting your example structure and with a > plain query (no grouping, no filtering, reduce on) I get back: > > { John: 4, Jane: 6 } Looks spot on! Thank you _so_ much for doing this. I'm really curious how this performs, I will be-siege my couch with bulk updates, giving it a big-ish data set while simultaneously be-siege it with reads GETs querying this map/reduce you've created. Will be very interesting. I'm still puzzled, though. When reading up on reduces, I got put off doing anything fancy in the reduce function as the guide on http://guide.couchdb.org/draft/views.html#example/3 states: "A common mistake new CouchDB users make is attempting to construct complex aggregate values with a reduce function. Full reductions should result in a scalar value, like 5, and not, for instance, a JSON hash with a set of unique keys and the count of each." And from my understanding, this is exactly what I want to do here, but perhaps I'm misunderstanding the author's meaning here? Cheers, -Torstein