Return-Path: Delivered-To: apmail-incubator-couchdb-user-archive@locus.apache.org Received: (qmail 58076 invoked from network); 9 Nov 2008 21:37:30 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 9 Nov 2008 21:37:30 -0000 Received: (qmail 9823 invoked by uid 500); 9 Nov 2008 21:37:36 -0000 Delivered-To: apmail-incubator-couchdb-user-archive@incubator.apache.org Received: (qmail 9792 invoked by uid 500); 9 Nov 2008 21:37:36 -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 9781 invoked by uid 99); 9 Nov 2008 21:37:36 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 09 Nov 2008 13:37:36 -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 sho.fukamachi@gmail.com designates 209.85.146.179 as permitted sender) Received: from [209.85.146.179] (HELO wa-out-1112.google.com) (209.85.146.179) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 09 Nov 2008 21:36:17 +0000 Received: by wa-out-1112.google.com with SMTP id l24so1060165waf.12 for ; Sun, 09 Nov 2008 13:36: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:from:to :content-type:content-transfer-encoding:mime-version:subject:date :x-mailer; bh=NLKehu+IToAnFixl0HKd2h3dMQy0Emj0vEVuhoCCPBM=; b=CUnNRtYjIfQg+sXNbEv8/kVwq25/Y5/nK4GYGcCFmXgUvdbP/to0pJmnY0YiHDmInG xIDnTR3ixfBlPKcVyzyVEWR11//hRmzwcnm9mMXzDza2a4zaUnZ78S/KHwIgx64FFIEI xNUAxBhc6+GsbLi4yrP7aqeXJFvjIFNpCknds= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:from:to:content-type:content-transfer-encoding :mime-version:subject:date:x-mailer; b=p07YIF1aSnUNCzkWXofxPWzcj79fbudSUfi+ZwyEfiDneo1Z07l7Dh8TXBbAU+lVME R+ClJHR9S7c2U7uNQ1q1QZo2DZoFk+K9IvyqVfoL3dIsv/WF1aXA48TAC09IwIVuNHGH vQ5wf5rpMDeWOiG+vlnwPUrAYsTiIsshbiZm4= Received: by 10.114.131.11 with SMTP id e11mr3639252wad.75.1226266610433; Sun, 09 Nov 2008 13:36:50 -0800 (PST) Received: from ?10.1.1.8? (124-171-24-148.dyn.iinet.net.au [124.171.24.148]) by mx.google.com with ESMTPS id n20sm10581789pof.27.2008.11.09.13.36.48 (version=TLSv1/SSLv3 cipher=RC4-MD5); Sun, 09 Nov 2008 13:36:49 -0800 (PST) Message-Id: From: Sho Fukamachi To: couchdb-user@incubator.apache.org Content-Type: text/plain; charset=US-ASCII; format=flowed; delsp=yes Content-Transfer-Encoding: 7bit Mime-Version: 1.0 (Apple Message framework v929.2) Subject: dual purpose filter/count views Date: Mon, 10 Nov 2008 08:36:46 +1100 X-Mailer: Apple Mail (2.929.2) X-Virus-Checked: Checked by ClamAV on apache.org Hi all, This is probably a really simple question, but for some reason* I can't figure it out. (* reason is most like extreme dumbness on my part) I've got a bunch of views where i have something like this: get_all_by_field: map: if (doc.type == 'my_doc') emit(doc.field, doc); count_all_by_field: map: if (doc.type == 'my_doc') emit(doc.field, 1); reduce: function(keys, values) { return sum(values) } That works fine, but seems like it could be more elegant .. I thought I'd be "clever" and try to combine the two, so I could get the "search" output by calling the map alone, and then getting the count by turning on reduce, something like this: map: function(doc) { if (doc.type == 'my_doc') emit(doc.field, [doc, 1]); } reduce: function(keys, values) { return sum(values[1]) } The idea being that if i turn off reduce, it outputs the docs I want, but if I turn it on, I can just count the second element in the emitted array. But for some reason it doesn't work. I've tried the above, just returning values[1], trying to sum values[0][1], etc. I either get errors or nothing. This is probably some really simple thing that I'm missing in my tired state. Can anyone give me a hint as to what it is? : ) thanks! Sho