incubator-couchdb-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Ben Bangert <...@groovie.org>
Subject Re: Associating users and comments
Date Thu, 02 Oct 2008 03:12:06 GMT
On Oct 1, 2008, at 8:00 PM, Chris Anderson wrote:

> http://wiki.apache.org/couchdb/Views
>
> The reduce docs are somewhat lacking...

I did read those.... let me be more specific, I have a few documents  
with key/value pairs like so:

_id	"097337c75773737022bb4e8cd3a92140"
_rev	"3161423366"
created	"2008-10-01T19:40:25Z"
last_login	"2008-10-01T19:40:25Z"
name	"Joe"
type	"Human"

_id	"3fefb1f90316b029b7937c01964e4fd8"
_rev	"2184850695"
created	"2008-10-01T19:40:25Z"
last_login	"2008-10-01T19:40:25Z"
name	"Fred Smith"
type	"Human"
username	"fsmith"

_id	"dd7d49e84929231c4384216e8dfbb133"
_rev	"1337790890"
code	"This is a sample"
created	"2008-10-01T19:40:25Z"
human_id	"097337c75773737022bb4e8cd3a92140"
language	"text"
title	"Sample 1"
type	"Paste"


Now, I can easily use the view collation to have a list of all the  
users and their 'Paste's that go with them, no prob. I get how the  
keys influence sort and such by having a map function like so (to get  
me the info I want for each one):

function(doc) {
   if (doc.type == 'Human') {
     emit([doc._id, 0], {type:doc.type, name:doc.name})
   } else if (doc.type == 'Paste') {
     emit([doc.human_id, 1], doc);
   }
}

Now, how would I filter this list, so that I don't get all the Humans  
with zero paste's filed for them? Ie, I only want the human row in the  
result set if there's going to be a Paste type row following it.

Alternatively, how would I have it return only 5 Paste's max for each  
user?

Thanks,
Ben
Mime
View raw message