Return-Path: Delivered-To: apmail-couchdb-user-archive@www.apache.org Received: (qmail 44035 invoked from network); 12 Nov 2010 01:06:58 -0000 Received: from unknown (HELO mail.apache.org) (140.211.11.3) by 140.211.11.9 with SMTP; 12 Nov 2010 01:06:58 -0000 Received: (qmail 81435 invoked by uid 500); 12 Nov 2010 01:07:26 -0000 Delivered-To: apmail-couchdb-user-archive@couchdb.apache.org Received: (qmail 81397 invoked by uid 500); 12 Nov 2010 01:07:26 -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 81389 invoked by uid 99); 12 Nov 2010 01:07:26 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 12 Nov 2010 01:07:26 +0000 X-ASF-Spam-Status: No, hits=2.9 required=10.0 tests=HTML_MESSAGE,RCVD_IN_DNSWL_NONE,SPF_NEUTRAL X-Spam-Check-By: apache.org Received-SPF: neutral (athena.apache.org: local policy) Received: from [74.125.82.54] (HELO mail-ww0-f54.google.com) (74.125.82.54) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 12 Nov 2010 01:07:21 +0000 Received: by wwb28 with SMTP id 28so130011wwb.23 for ; Thu, 11 Nov 2010 17:06:59 -0800 (PST) MIME-Version: 1.0 Received: by 10.216.17.204 with SMTP id j54mr2811337wej.108.1289524019150; Thu, 11 Nov 2010 17:06:59 -0800 (PST) Received: by 10.216.30.79 with HTTP; Thu, 11 Nov 2010 17:06:59 -0800 (PST) In-Reply-To: References: Date: Thu, 11 Nov 2010 20:06:59 -0500 Message-ID: Subject: Re: First doc in a group? From: Chad George To: user@couchdb.apache.org Content-Type: multipart/alternative; boundary=00163649a3e31741760494d0b53c --00163649a3e31741760494d0b53c Content-Type: text/plain; charset=ISO-8859-1 After a little reflection, maybe my original response was a little too strong. You might need to use a reduce if you want the latest document for a whole set of users in a single call. If you only wanted the latest document for a single user, then the view+key ranges+limit=1 is definitely the best approach. Maybe Cory's idea is the best approach. A reduce function that calculates the latest document (maximum timestamp) and also use group=True or group_level=1 (depending on the final view key structure used) -Chad On Thu, Nov 11, 2010 at 6:29 PM, Mike Bannister wrote: > Cool, I understand now reduce isn't right, initially posted to the list > because I couldn't decide that on my own. > > So what's the most efficient way to get the latest document for each user? > Seems like I shouldn't have to do one query per user but I'm open minded (: > > -Mike > > > > On Thu, Nov 11, 2010 at 5:52 PM, Chad George wrote: > > > Selecting one row in a view out of many possible isn't what reduce is > for. > > > > I try not to think of it as reducing a set of view results to a smaller > set > > but rather reducing each and every entry in the view to something > smaller. > > > > The fact that reduce gets multiple view rows to work on at once is just > an > > optimization. I think its better to think of reduce as working on exactly > > one view row at a time then rereduce the result to get final answer. > > On Nov 11, 2010 5:22 PM, "Mike Bannister" > wrote: > > > Cory, cool thanks. Wasn't able to decide on my own if reducing was OK > for > > > this kind of thing. > > > > > > Robert, but I need one document for each user, wouldn't that be a > summary > > of > > > sorts? > > > > > > -Mike > > > > > > > > > On Nov 11, 2010 4:46 PM, "Cory Zue" wrote: > > > > > > You could emit the users as keys, and in your reduce function just > > > return the latest by date. > > > > > > > > > On Thu, Nov 11, 2010 at 4:35 PM, Mike Bannister < > mikebannister@gmail.com > > > > > > wrote: > > >> Yeah, I'm trying... > > > --00163649a3e31741760494d0b53c--