Return-Path: Delivered-To: apmail-couchdb-user-archive@www.apache.org Received: (qmail 42342 invoked from network); 11 Nov 2010 21:45:58 -0000 Received: from unknown (HELO mail.apache.org) (140.211.11.3) by 140.211.11.9 with SMTP; 11 Nov 2010 21:45:58 -0000 Received: (qmail 60617 invoked by uid 500); 11 Nov 2010 21:46:28 -0000 Delivered-To: apmail-couchdb-user-archive@couchdb.apache.org Received: (qmail 60594 invoked by uid 500); 11 Nov 2010 21:46:28 -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 60586 invoked by uid 99); 11 Nov 2010 21:46:28 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 11 Nov 2010 21:46:28 +0000 X-ASF-Spam-Status: No, hits=2.1 required=10.0 tests=DNS_FROM_RFC_BOGUSMX,RCVD_IN_DNSWL_NONE,SPF_NEUTRAL X-Spam-Check-By: apache.org Received-SPF: neutral (athena.apache.org: local policy) 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, 11 Nov 2010 21:46:24 +0000 Received: by iwn37 with SMTP id 37so2665407iwn.11 for ; Thu, 11 Nov 2010 13:46:02 -0800 (PST) MIME-Version: 1.0 Received: by 10.42.172.65 with SMTP id m1mr1358861icz.342.1289511958157; Thu, 11 Nov 2010 13:45:58 -0800 (PST) Received: by 10.42.169.4 with HTTP; Thu, 11 Nov 2010 13:45:58 -0800 (PST) In-Reply-To: References: Date: Thu, 11 Nov 2010 16:45:58 -0500 Message-ID: Subject: Re: First doc in a group? From: Cory Zue To: user Content-Type: text/plain; charset=ISO-8859-1 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 wrote: > Yeah, I'm trying to get the latest document for each user in one query > rather than one query per user. > > On Thu, Nov 11, 2010 at 4:11 PM, Matthew Woodward wrote: > >> On Thu, Nov 11, 2010 at 12:59 PM, Mike Bannister > >wrote: >> >> > I have a set of documents that are related to users in my system and each >> > document has a timestamp. What's the CouchDB way of getting the latest >> > document for each user? >> >> >> I'm pretty new to CouchDB as well so take this for what it's worth--in one >> of our databases we needed to get the most recent document based on a >> timestamp, so we just have a view called "byDate" with the key being the >> timestamp, and then we just call the view like this: >> >> http://server/database/_design/designname/_view/byDate?descending=true&limit=1 >> >> Not sure that's quite what you're after and might not address the user part >> of what you're doing, but hope that helps a bit. >> >> -- >> 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 >> >