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 <[email protected]> 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 
> <[email protected]>wrote:
>
>> On Thu, Nov 11, 2010 at 12:59 PM, Mike Bannister <[email protected]
>> >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
>> [email protected]
>> 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
>>
>

Reply via email to