Return-Path: Delivered-To: apmail-couchdb-user-archive@www.apache.org Received: (qmail 24570 invoked from network); 20 Jan 2011 06:22:32 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 20 Jan 2011 06:22:32 -0000 Received: (qmail 4607 invoked by uid 500); 20 Jan 2011 06:22:30 -0000 Delivered-To: apmail-couchdb-user-archive@couchdb.apache.org Received: (qmail 4253 invoked by uid 500); 20 Jan 2011 06:22:27 -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 4245 invoked by uid 99); 20 Jan 2011 06:22:26 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 20 Jan 2011 06:22:26 +0000 X-ASF-Spam-Status: No, hits=2.2 required=10.0 tests=HTML_MESSAGE,RCVD_IN_DNSWL_LOW,SPF_NEUTRAL X-Spam-Check-By: apache.org Received-SPF: neutral (athena.apache.org: local policy) Received: from [74.125.82.180] (HELO mail-wy0-f180.google.com) (74.125.82.180) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 20 Jan 2011 06:22:21 +0000 Received: by wyb28 with SMTP id 28so266004wyb.11 for ; Wed, 19 Jan 2011 22:22:00 -0800 (PST) MIME-Version: 1.0 Received: by 10.227.126.204 with SMTP id d12mr1847848wbs.174.1295504518178; Wed, 19 Jan 2011 22:21:58 -0800 (PST) Received: by 10.227.150.103 with HTTP; Wed, 19 Jan 2011 22:21:58 -0800 (PST) X-Originating-IP: [156.33.195.149] In-Reply-To: <0269751D-4D71-4B4B-947A-3530AE083EB3@apache.org> References: <0269751D-4D71-4B4B-947A-3530AE083EB3@apache.org> Date: Wed, 19 Jan 2011 22:21:58 -0800 Message-ID: Subject: Re: Writing View to Get Unique Values in Arrays Across Documents From: Matthew Woodward To: user@couchdb.apache.org Content-Type: multipart/alternative; boundary=90e6ba1ef89c9c6640049a4126f0 --90e6ba1ef89c9c6640049a4126f0 Content-Type: text/plain; charset=ISO-8859-1 On Wed, Jan 19, 2011 at 3:48 PM, Jan Lehnardt wrote: > > http://guide.couchdb.org/editions/1/en/cookbook.html#unique I'm sure I'm doing something wrong but for the life of me I can't get that example to work. It seems to choke when I try to emit each item in the array as a variable name in the forEach loop. For example, this works but isn't what I want to output. Just tried this to see if the forEach was working which based on the document count I get back it seems to be. { "byOffice": { "map": "function(doc) { if (doc.office != '' && doc.witnesses != '[]') { doc.witnesses.forEach(function(witness) { emit(doc.office, null);}); }}" } } So that outputs doc.office for each witness which isn't what I want, but as I said based on the guesstimate of the rows returned compared to what I know about the data that seems to be more or less accurate. So the loop is working at least. When I change to this, however, things fail: { "byOffice": { "map": "function(doc) { if (doc.office != '' && doc.witnesses != '[]') { doc.witnesses.forEach(function(witness) { emit(witness, null);}); }}" } } In Firefox I get a blank white screen and view source is empty, but in Chrome it shows this error detail: Error 324 (net::ERR_EMPTY_RESPONSE): Unknown error. It doesn't seem like it'd be an issue with it returning too many documents since the forEach works with other data (and returns ~12,000 rows), so my guess is I'm missing a fundamental piece of how this all works. I'll be added a reduce function once I get this piece working if that makes any difference, because ultimately I want the unique values, but for now I'm happy just seeing them all returned including dupes. Thanks. -- Matthew Woodward matt@mattwoodward.com http://blog.mattwoodward.com identi.ca / Twitter: @mpwoodward Please do not send me proprietary file formats such as Word, PowerPoint, etc. as attachments. http://www.gnu.org/philosophy/no-word-attachments.html --90e6ba1ef89c9c6640049a4126f0--