From couchdb-user-return-1143-apmail-incubator-couchdb-user-archive=incubator.apache.org@incubator.apache.org Wed Aug 27 01:20:58 2008 Return-Path: Delivered-To: apmail-incubator-couchdb-user-archive@locus.apache.org Received: (qmail 85971 invoked from network); 27 Aug 2008 01:20:58 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 27 Aug 2008 01:20:58 -0000 Received: (qmail 67612 invoked by uid 500); 27 Aug 2008 01:20:56 -0000 Delivered-To: apmail-incubator-couchdb-user-archive@incubator.apache.org Received: (qmail 67584 invoked by uid 500); 27 Aug 2008 01:20:56 -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 67572 invoked by uid 99); 27 Aug 2008 01:20:56 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 26 Aug 2008 18:20:56 -0700 X-ASF-Spam-Status: No, hits=2.0 required=10.0 tests=HTML_MESSAGE,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: local policy) Received: from [206.210.85.213] (HELO smtp1.nviznit.com) (206.210.85.213) by apache.org (qpsmtpd/0.29) with SMTP; Wed, 27 Aug 2008 01:19:58 +0000 Received: from [192.168.0.129] (c-71-60-56-89.hsd1.pa.comcast.net [71.60.56.89]) by smtp1.nviznit.com (Postfix) with ESMTPSA id AB0481BD898 for ; Tue, 26 Aug 2008 17:33:22 -0400 (EDT) Message-ID: <48B4ABDA.7070500@visn.biz> Date: Tue, 26 Aug 2008 21:20:26 -0400 From: Joel Reed User-Agent: Thunderbird 2.0.0.16 (X11/20080725) MIME-Version: 1.0 To: couchdb-user@incubator.apache.org Subject: Re: using reduce to get SQL distinct like results References: <48B46F44.2030309@visn.biz> <20080826215316.GF2126@ginosko.ndrix.org> In-Reply-To: <20080826215316.GF2126@ginosko.ndrix.org> Content-Type: multipart/alternative; boundary="------------040101060405080504080503" X-Virus-Checked: Checked by ClamAV on apache.org --------------040101060405080504080503 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Michael Hendricks wrote: > On Tue, Aug 26, 2008 at 05:01:56PM -0400, Joel Reed wrote: > >> I have a bunch of documents that look vaguely like this: >> >> [{ "User":"Jane Doe", "Date":"2008/08/12", } { "User":"Jane Doe", >> "Date":"2008/08/15", }, etc...] >> >> IOW, There might be several entries for each user all with different dates. >> >> I'd like tp combine all "Jane Doe's" records into 1 entry. Some kind of >> output like: >> >> "rows": [ {"key": "Jane Doe", "value": [ >> {"id":"481bf9e8a0c23bb61eeed4b3707bae59","Date":"2008/08/12"}, >> {"id":"1e6e541b391efcb9c137d7097e7de6ed","Date":"2008/08/15"} >> ] } ] >> > > How about something like this: > > "all": { > "map": "function(doc) { emit(doc.User, doc.Date); }", > "reduce": "function(keys, values) { > var results = new Array(); > for ( var i in values ) { > results.push({ > id : keys[i][1], > Date : values[i] > }); > } > > return results;" > } > } Thanks Michael, I'll give this a try. The results look alot nicer. jr --------------040101060405080504080503--