From user-return-10914-apmail-couchdb-user-archive=couchdb.apache.org@couchdb.apache.org Thu Jun 10 12:31:43 2010 Return-Path: Delivered-To: apmail-couchdb-user-archive@www.apache.org Received: (qmail 30462 invoked from network); 10 Jun 2010 12:31:43 -0000 Received: from unknown (HELO mail.apache.org) (140.211.11.3) by 140.211.11.9 with SMTP; 10 Jun 2010 12:31:43 -0000 Received: (qmail 53641 invoked by uid 500); 10 Jun 2010 12:31:42 -0000 Delivered-To: apmail-couchdb-user-archive@couchdb.apache.org Received: (qmail 53298 invoked by uid 500); 10 Jun 2010 12:31:39 -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 53289 invoked by uid 99); 10 Jun 2010 12:31:38 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 10 Jun 2010 12:31:38 +0000 X-ASF-Spam-Status: No, hits=1.8 required=10.0 tests=AWL,FREEMAIL_FROM,HTML_MESSAGE,SPF_PASS,T_TO_NO_BRKTS_FREEMAIL,WEIRD_PORT X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: domain of moritzpost@gmail.com designates 209.85.214.180 as permitted sender) Received: from [209.85.214.180] (HELO mail-iw0-f180.google.com) (209.85.214.180) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 10 Jun 2010 12:31:32 +0000 Received: by iwn38 with SMTP id 38so2034631iwn.11 for ; Thu, 10 Jun 2010 05:31:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:received:date:message-id :subject:from:to:content-type; bh=dTPfD8ge1r2ppZO8iJbss+ELvjKxN4R892adrfsOl3U=; b=juOlcyNro9tYEKEmMuCkcV0ZtMrOr54f2Xsr+0d6EztTRUSe3T1TiJqF1ZzXDlFAAx kTHGKgkUR1bFje4O4C1PIxn1lJoJk6f0YJbjy3bJLiGCOIxpd03M5iRLnq/+walvlWW8 SHTwF3ByVMghaJgQhcnqMRHSFEgiMsa8c0VjU= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:date:message-id:subject:from:to:content-type; b=dEjg3vW5ccreMeIIhrL6Z/BCqa+9hiVBO+Kq9UQL/YO1PhDQBxD/Qcm1e0suIqDKm1 pPctnOXqoNwAp3GyqsJjNE5B2ghr5pAXIgzdsjHwWedOjJxdNfHrbmRttNTpwtsD5NKu vh7Tc2VEPOlKIGTOQEEOLCLtoA4Oo5WFUqJWQ= MIME-Version: 1.0 Received: by 10.231.196.220 with SMTP id eh28mr34542ibb.198.1276173071430; Thu, 10 Jun 2010 05:31:11 -0700 (PDT) Received: by 10.231.143.18 with HTTP; Thu, 10 Jun 2010 05:31:10 -0700 (PDT) Date: Thu, 10 Jun 2010 14:31:10 +0200 Message-ID: Subject: Calculating the sum of attachment sizes From: Moritz Post To: user@couchdb.apache.org Content-Type: multipart/alternative; boundary=001636e0a8889835580488ac3214 --001636e0a8889835580488ac3214 Content-Type: text/plain; charset=ISO-8859-1 Hi CouchDB I want to calculate the sum of all attachments of a particular subset of documents. Here is my approach: == Map == function(doc) { var localSum = 0; for ( var i in doc._attachments) { localSum += doc._attachments[i].length } emit(doc._id, localSum); } == Reduce == function(key, values) { return sum(values) } This works fine when i run this code from within futon without providing any subset of docs. It returns a single result { null, } But what i do in practice is using a POST on the view to provide the ids of documents of which totalsum i am interested in (eg 2 docs here): curl -d '{"keys":["a813cded7cfa807c6c48ae1d84004d45","a813cded7cfa807c6c48ae1d84001823"]}' -X POST http://localhost:5984/mydb/_design/mydesign/_view/getAttachmentSize?group=true Here is the problem: I have to use group=true when calling the view with POST parameters because it is a multi-key fetch (otherwise the couch complains). In this results i get a separate result entry for each document since the grouping keys are obviously different for each doc._id. So i get something like: "a813cded7cfa807c6c48ae1d84004d45", 68346 "a813cded7cfa807c6c48ae1d84001823", 23755 but not the aggregated sum. I have to use the doc._id in the emit function though because otherwise the filtering via the POST parameter would not limit the sum to the document subset i specified. So i hope one understands the problem and is able to point me in the right direction. If their is any better way to calculate the sum of all attachments sizes for a subset of documents i would also be very interested. Thanks in advance Moritz Post --001636e0a8889835580488ac3214--